The use of templates

From: Date: Wed, 14 Feb 2001 11:14:00 +0000
Subject: The use of templates
Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-123@lists.php.net to get a copy of this message
Hello, I have a situation where I think I could use templates. Basically, it's about displaying a list of projects on a webpage; every project has a couple of properties, as well as a list of people that are active in the project. This means that I will have a "doube-loop": list every project, and for every project, list its members. As far as I know, the big advantage of using templates is the fact that you can very easily separate code from presentation. That means that I would like to have one "main" template to list the projects, and for every project listed, I'd like to include a "sub-template" for the members list. However, using Smarty, I don't really know how to do this. You might say I could use two loops, one inner, and one outer, which would look like this (taken from QUICKSTART): <-- snip --> --------- templates/index.tpl -------- {include file="header.tpl" title="Home Page"} {section name=people loop=$FirstName} {%people.rownum%} {$people/FirstName} {$people/LastName}<br> {section name=contacts loop=$people/ContactNames} {* for fun, lets bold every other row *} {if %contacts.rownum% is even}<b>{/if} {$people/contacts/ContactNames}: {$people/contacts/ContactVals}<br> {if %contacts.rownum% is even}</b>{/if} {/section} <br> {sectionelse} There are no values to loop through. {/section} <p> There were {%people.loop%} names in this list. {include file="footer.tpl"} <-- snip --> However, where's the separation between code and presentation here? I can't possibly give this file to our graphics designer, he won't understand anything. The above -is- code, even if it's not PHP, it is still code. How shall I proceed ? It would be great if I could have something like: * project_list.tpl that is the "big template" for the projects list * member_list.tpl that is the "small template", included for every project above. These files would be made of HTML and {$Variable} tags, nothing more. Anything more "complex" and our graphics guy dies :). Thanks for your input ! ------ Alain Fontaine Analyst-Programmer NVision s.à.r.l.

« previous php.smarty.general (#123) next »