RE: Template System

Brenden <[email protected]> 31 Jul 2003 21:49:15 -0000
Newsgroups gmane.comp.web.oscommerce.devel
Message-ID <c25ff5d7f5f08d0395475f8783f6d7f0@osCommerce-Forums>
This message was sent from: Development
http://forums.oscommerce.com/viewtopic.php?p=205238#205238
----------------------------------------------------------------

[quote="wdingus"]A lot of what it boils down to centers around how easy it is to intermingle static and dynamic output. In your top.php example Brenden it's all static content. Depending on how intermingled the dynamic data is with the static 'presentation' of the site/store, this approach could get somewhat cumbersome. Looks like you'd end up having to have some php logic in that file after all, which defeats the purpose of a template at least somewhat.

For me it's important what my graphics designers get to touch and what they don't. It makes me cringe to think of them loading any file with a .php extension and/or manipulating our code inside their graphical web editing software packages. I have no problem with them defining where on a detail page the picture of the item displays and the font size/shape and placement of the description text of it, I'd just prefer they do this _without_ messing with code at all![/quote]

An advanced template using smarty has logic in it.  I guess it would be called smarty logic and not php logic.

Smarty Logic:
[code]{section name=mysec loop=$users}
{strip}
   <tr>
      <td>{$users[mysec].name}</td>
      <td>{$users[mysec].phone}</td>
   </tr>
{/strip}
{/section}[/code]

PHP logic:
[code]<?php while ($result = tep_db_fetch_array($query)) { ?>
    <tr>
      <td><?php echo $result['name'] ?></td>
      <td><?php echo $result['phone'] ?></td>
   </tr>
<?php  } ?>[/code]

One of the problems with a template engine is that it has to parse the entire template looking for anything between { and } .  This creates an increased load time.  You might say that that is true but you can cache the page.  Realisticly, you wouldnt have to cache the page if smarty wasnt used.

Whether you tell designer not to touch anything in between { and } or <?php and ?> makes little difference in my view.  But remember with smarty you have to teach you developer to learn smarty aswell as your designer.