a smarty example

pngwen <[email protected]> 31 Jul 2003 12:25:39 -0000
Newsgroups gmane.comp.web.oscommerce.devel
Message-ID <ce3c5628af7a1064c99d4fd5c81c61ca@osCommerce-Forums>
This message was sent from: Development
http://forums.oscommerce.com/viewtopic.php?p=205008#205008
----------------------------------------------------------------

Ok, here's a smarty example  of a top level template.  You'd have something like this:


[code]
<html><body>
{include file="top.tpl"}
<table>
<tr>
<td> {include file="left.tpl}</td>
<td> {include file=$content}</td>
<td> {include file="right.tpl"}</td>
</tr>
</table>
{include file="bottom.tpl"}
</body></html>

[/code]


So basically you get that simple table in there and then you have the one file to edit to change the page structure.  Editing top.tpl, left.tpl and right.tpl yield differing results inside the page.  The difference with smarty is that you pass in the information available to the template (like the content variable which tells the template what file to use in the main content area) and then that information can be displayed anyway the web designer chooses.  

It looks a bit like php, but it's a much more easily understood subset of php, one that is muh more easily grasped by designers.  Also, if you look at the above in a web browser without the smarty template engine running it, you see the tables along with your variables and smarty tags in the same places they would appear otherwise.  Most browsers go nuts when they see a php begin tag and there is no way to predict how that is going to work.

Also, as wdingus said, you can edit these files with editors like dreamweaver.  There are plugins for them that will generate the smarty code even!  So what we need is something to pass a standard set of variables to the smarty class, then the designers can do what they will with them.  That is part of what I am doing, as well as sifting through the code and identifying elements that remain constant on every page, so that it only winds up in the template system once.