Chris W. Parker wrote:
Chris de Vidal <mailto:[EMAIL PROTECTED]>
    on Tuesday, April 06, 2004 11:43 AM said:


I could have put a tag in the template like {bio} but that'd mean
maintaining HTML in the PHP code which I wanted to avoid (left the
"prettyness" to the Front Page developer).  Instead, I put something
like this in the template:
{if $level > 2}
{bio}
{/if}


i've never used smarty* but i think i understand how it works. so my
question is this...

would it not be better to place that logic in your php code instead of
your template?

what you suggest is handy for situations where you want to limit access to anything remotely programmy from users/designers who have no understanding/experience etc (or who use tools like FrontPage...yuck!)
(Maybe DreamWeaver is a better option, has better HTML output/processing and can be made to work nicely with Smarty templates.)


BUT...

It's probably important to understand that templating is really about the seperation of presentation & application/business logic in order to allow, for example, better task seperation (interface/graphic designers edit templates and programmers edit PHP files) and not about the seperation of code & content (or HTML & PHP or somesuch): it is true that most ('so called' -- not all are really template engines) allow you to also seperate the HTML & PHP.

bare this in mind: PHP is also a templating engine! image 1 file which does calculation, DB transactions and setting output variables and another file which outputs HTML according to logic that reacts to the values of the output variables.

to me performance is second to everything else (I prefer slow code thats well documented, loosely coupled* and easily extentable to super fast unreadable tightly coupled code) - first make it do what you need it to do! you can always optimize later and if the code is still not fast enough then code accelerators (like the ZendAccelerator or PHPa) and faster hardware probably offer the cheapest (and mostly quickly implemented) performance boost.

I think Smarty is a really good tool and very well supported & documented. I have run into limitations regarding PHP5 dereferenced object syntax and static object call syntax which led me to investigate the template parsing mechanism of Smarty - I found regular expressions which exceeded 1000 chars in length!! this I found to be a little worrying, none the less Smarty is still faster & I see very little slowdown even when forcing a recompile on every page hit as opposed to not using Smarty at all.

I hope that adds to you understanding a bit. If anything is unclear or I have stated something that is incorrect I'd love to hear about it -- always looking to learn more about stuff, especially PHP!

Jochem

--
*coupling refers to the level of interdependency of various elements with you application. using Smarty _allows_ you to loosen the coupling between business & presentation logic (you can technically write all your business logic in Smarty templates but that is ill-advised) by creating a std API for transfering data from one layer to the next.


my thinking is this: if {bio} contains anything, it will print to the
page. if it doesn't contain anything, nothing will be printed. so
there's no need to check the value of $level within the template since
{bio} will simply contain something, or it will not.

i'm purely looking to understand this "smarty" thing a little better. :)


chris.

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



Reply via email to