|
Posted by Mike P2 on 05/05/07 21:53
On May 5, 9:27 am, webcm...@gmail.com wrote:
> I think how to attach document body to the template. The previous
> method don't allow to change <title>, add headers or code to <head>.
> However, it has some advantages - modules don't care about including
> template or defining FILE constant.
>
> [url]http://nopaste.php-quake.net/236[/url] - there are the methods
> with advantages and disadvantages
>
> What should I choose? I want a good fast method. The performance is
> important. Can you give me some advices? :)
For quick solutions, I have a directory for all templates, and within
that directory another directory for every layout. Within each layout
directory, I would have several files, something like this:
-/layouts/layout1/head.tpl: <!doctype...><html><!--common head stuff--!
>
-/layouts/layout1/header.tpl: </head><body><!--page header-->
-/layouts/layout1/footer.tpl: <!--page footer--></body></html>
Sometimes I don't include </head><body> in heade.tpl, it shouldn't
matter much. Then I either set $template = 'layout1' in a common.php
file and include( "/layouts/$template/whatever.tpl" ) wherever it
should go on the page. Sometimes I just readfile() them in if there is
no PHP code in the .tpl files, which should be more efficient. You can
also file_get_contents() the files into variables in the common.php
file and then echo them, but then you have a lot of crap in memory.
That is what I generally do for small, 5-10 page sites for businesses
and stuff. Otherwise, I will use Smarty template engine or something
similar (something similar usually means TemplateLite, which is faster/
more efficient than Smarty). These template engines are the most
advanced way to template your website. They are generally designed so
you have to keep most HTML separate from PHP files. They are fast
enough when you use them right.
http://smarty.php.net/
http://templatelite.sourceforge.net/
-Mike PII
Navigation:
[Reply to this message]
|