Update:Archive/2.0/Developers/Templates
Update: Home Page » Suggestions » Templates
Templates
A template engine for the web should meet certain criteria.
http://wact.sourceforge.net/index.php/GoodTemplateSmells
- Pass the Dreamweaver test.
- Simplicity.
- Validating.
- Cacheable.
- Self-Inspecting.
- Secure.
- Flexibility.
Templating Engines for Consideration
- PHP (yep PHP itself is a template engine)
- [[1]]
- XSLT - technically XSLT is also a template engine
- [[2]]
- [[3]]
- [[4]]
- [[5]]
- [[6]]
- [[7]]
- [[8]] (port of Zope templates)
- [Savant] - reclaiming PHP
- [[9]] - also reclaiming PHP
- [- Yet Another PHP Templating System]
- [[10]] (yet another yet another?)
- [Template] (French)
- [[11]]
- [- Easy Template System]
- [[12]]
- [[13]]
- [[14]]
- [[15]]
- [[16]]
- [[17]]
- [Template] (part of a mini framework)
- [[18]]
- [Template]
- [[19]]
- [[20]]
- [[21]]
- [[22]]
- [[23]]
- [[24]]
- [template]
- [[25]]
- [[26]]
- [[27]]
- [Wrapper]
- [[28]]
- [Template]
- [[29]]
- [template engine]
- [Template]
- [Clone] - drop in replacement for FastTemplate.
- [But Strong]
- [Turtle Template]
- [[30]]
- [[31]]
- [Power]
- [[32]]
- [Hayes Template class]
- [Template] (site is down? [entry])
- [[33]]
- [[34]]
- [[35]]
- eZ Publish 2.x Templates
- [Publish 3.x Templates] - very different to 2.x
- [[36]]
- [Template]
- [Template] - not sure about this one - seems to be about turning PHP into an intepreter
- [[37]] (formerly known as ShellPage)]]
- PHP-DOM extension (HTML support)
- [[38]]
- [(former Apolda Template)]
- [Template]
- [Template Compiler]
- [[39]]
- [[40]] - implements it's own template engine
- [[41]]
- [[42]]
- [[43]]
- [[44]]
- [Side Template Parser]
- [Object Oriented Templates]
- [[45]] - has it's own template langauge
- [[46]]
- [[47]]
Discussion
http://www.sitepoint.com/forums/showthread.php?threadid=123769
http://wact.sourceforge.net/index.php/TemplateView
morgamic's take
A solid application structure could eliminate the need for a comprehensive templating engine. Wrapping HTML output is a relatively simple task done by using includes in parallel with proper use of CSS. I always question templating that extends beyond that in terms of complexity.
As with PEAR::DB or adodb, I think the use of a templating engine should only be considered if it is the right thing to do.
That said, I question whether adding the layer of complexity and adding another dependency is really necessary if we can use CSS for all of our presentation.
Don't get me wrong -- I'd definitely like to se HTML wrapped in functions where appropriate and a good segregation of PHP and HTML in order to have some sort of uniformity and structure when it comes to each .php script. I think that is a great goal and should definitely be realized in any good application.
But if we can use CSS properly, all HTML output will be exactly the same with the exception of DOM identifiers when appropriate, using templating or skinning the whole app should be reduced to a matter of switching stylesheets. From there, it's just a matter of packaging your markup properly, which is not something I see us needing a separate tool for.
alanjstr's take
We definitely need to move from having the html all over the php. I don't think anyone will disagree with that. Templating allows us to separate the data from the presentation. I'm all for using CSS. But the html it applies to is what we need to work on.
The sidebar is an example. We have different kinds of sidebars. We have one for themes, one for extensions, one for developers ... Instead of us making a whole sidebar module that does echos, we can use a template that accepts data and turns it into presentation. Consider this example I wrote using Smarty
<!-- Insert Wrapper PHP Here -->
<div id="side"> <ul id="nav"> {* This is probably better off using nested arrays *} {section name=i loop=$categories} {if $categories[i].subcats[0]} <ul> {section name=j loop=$categories[i].subcats} <li><a href="showlist.php?{$uriparamsnocat}&category={$categories[i].subcats[j].catname}" title="{$categories[i].subcats[j].catdesc}">{$categories[i].subcats[j].catname}</a></li> {/section} </ul> {else} <li><a href="showlist.php?{$uriparamsnocat}&category={$categories[i].catname}" title="{$categories[i].catdesc}">{$categories[i].catname}</a></li> {/if} {/section} </ul> </div>
All we do is pass in an array of data, and the template determines how to present it. We don't clutter our code with echo statements.