Re: Question about template systems

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Matthew Croud wrote:
> Hello,
> 
> First post here, I'm in the process of learning PHP , I'm digesting a
> few books as we speak.
> I'm working on a content heavy website that provides a lot of
> information, a template system would be great and so i've been looking
> at ways to create dynamic data with a static navigation system.
> 
> So far, using the require_once(); function seems to fit the bill in
> order to bring in the same header html file on each page.
> I've also looked at Smartys template system.
> 
> I wondered how you folk would go about creating a template system ?
> 
> My second question might be me jumping the gun here, I haven't come
> across this part in my book but i'll ask about it anyway.  I often see
> websites that have a dynamic body and static header, and their web
> addresses end like this: "index.php?id=445" where 445 i presume is some my 
> file reference.
> What is this called ?  It seems like the system i'm after but it doesn't
> appear in my book,  If anyone could let me know what this page id
> subject is called i can do some research on the subject.
> 
> Thanks for any help you can provide :)
> 
> Matt.
>  

I have written a popular theme/template system for some CMS systems.  In
my opinion, templating is only needed for those that are totally
ignorant of the concept of programming languages in general.  It helps
for those designers that know HTML or they export their graphics as HTML
and know enough to modify it or add some simple tags like {post-date} to
HTML.  That's it!  No loops, no ifs, nothing.  Simple things
designers/users can add that represent some complex code, queries, etc...

PHP IS a template language.  You can easily separate your logic and
design/display using PHP.  Anything more than abstracting some complex
code to some simple var is overkill.  If you want to display a dropdown
of categories, and the code needed is a database query and some PHP
logic, etc., then it makes sense in my above scenario to do this in code
and then assign the result to a template var like {categories-dropdown}
that the designer/user can use in the HTML.  Other than that its just waste.

Smarty and similar template approaches just take PHP (but more limited)
and make it look slightly different.  Anyone who doesn't know or want to
know anything about programming will not see the difference between PHP
and Smarty.  Consider the following:

PHP: <?php echo $somevar; ?>

Smarty: {somevar}
//oh except in your PHP you have to do the following
//$smarty->assign('somevar', $somevar);
//$smarty->display('some.tpl');

PHP: include('header.tpl');

Smarty: {include file="header.tpl"}

Don't even get me started on loops and conditionals.  Smarty just
replicates PHP, except it looks slightly different and is much less
powerful.  If you are confused with:

if ($something) {
	echo "Some stuff...";
} else {
	echo "Some other stuff...";
}

Why is this better:

{if $something}
    Some stuff...
{else}
    Some other stuff...
{/if}

Like I said earlier, if you have some complex code that you can reduce
to a simple tag or something that a designer can insert into HTML then
great.  If not then it is just unsuccessfully trying to replicate PHP!
-- 
Thanks!
-Shawn
http://www.spidean.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux