Update:Archive/2.0/Developers/Templates
« Back to Archive | Update: Main
Contents
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)
- Smarty
- XSLT - technically XSLT is also a template engine
- PEAR::HTML_Template_Flexy
- PEAR::HTML_Template_IT
- PEAR::HTML_Template_PHPLIB
- PEAR::HTML_Template_Sigma
- PEAR::HTML_Template_Xipe
- patTemplate
- PHPTAL (port of Zope templates)
- PHP Savant - reclaiming PHP
- SimpleT - also reclaiming PHP
- YATS - Yet Another PHP Templating System
- YAPTER (yet another yet another?)
- Virtual Template (French)
- PHPLib
- ETS - Easy Template System
- AvantTemplate
- XTemplate
- htmltmpl
- Bleetz
- ASAPlate
- DTE
- Enzyme Template (part of a mini framework)
- PHP-Service
- Quick Template
- Sledgehammer
- PHPMarker
- TPLN
- FT
- ATemplate
- ctlTpl
- hierarchy template
- InTemplate
- lorenphplib_patternizer
- MyTemplate
- Path Wrapper
- phpoot
- Smart Template
- Templato
- phpBB template engine
- Fast Template
- FastTemplate Clone - drop in replacement for FastTemplate.
- Tiny But Strong
- Simple Turtle Template
- MiniTemplator
- TagTemplate
- Template Power
- vLibTemplate
- Richard Hayes Template class
- Bugi Template (site is down? hotscripts entry)
- bTemplate
- Phemplate
- Templeet
- eZ Publish 2.x Templates
- eZ Publish 3.x Templates - very different to 2.x
- TemplatePower
- Muze Template
- Logic Template - not sure about this one - seems to be about turning PHP into an intepreter
- varpage (formerly known as ShellPage)]
- PHP-DOM extension (HTML support)
- Template-X
- KTemplate (former Apolda Template)
- EZ Template
- 4Arrow Template Compiler
- dutchtpl
- Xaraya - implements it's own template engine
- ecTemplate
- Freetemplate
- ModelIxe
- PHPTempt
- Server Side Template Parser
- Vanilla Object Oriented Templates
- vBulletin - has it's own template langauge
- ExTemplates
- TemplateTamer
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.
- mvl's comments: A template engine is definitly worth it. It is not about CSS. It is about readable code. html all over the php code makes the php unreadable. php all over the html code makes the html unreadable. You really want to split it. (and having it split up reduces the risk of cvs conflicts) --Mvl 10:51, 22 Jan 2005 (PST)
- morgamic's comments: I think I may have not been thinking enough about the people responsible for UMO's design. The need for a good engine that can accomodate them and allow them the ability to change look and feel without mucking with CVS would be a great feature -- mconner helped explain that to me. UMO will be very different from Bouncer in that respect, so maybe I have to read up more on templating engines. :)
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
<!-- Incomplete PHP Wrapper --> include('Smarty.class.php'); $smarty = new Smarty; $smarty->assign('categories', array() )
<!-- Sample Template --> <div id="side"> <ul id="nav"> {section name=i loop=$categories} {if $categories[i].subcats[0]} <li><ul> {section name=j loop=$categories[i].subcats} <li><a href="showlist.php?category={$categories[i].subcats[j].catname}" title="{$categories[i].subcats[j].catdesc}"> {$categories[i].subcats[j].catname}</a></li> {/section} </ul></li> {else} <li><a href="showlist.php?category={$categories[i].catname}" title="{$categories[i].catdesc}">{$categories[i].catname}</a></li> {/if} {/section} </ul> </div>
<!-- Sample Output --> <div id="side"> <ul id="nav"> <li><a href="showlist.php?acategory=All" title="Show All Themes Alphabetically">All Themes</a></li> <li><ul> <li><a href="showlist.php?category=Animals" title="Animal Themes">Animals</a></li> <li><a href="showlist.php?category=Compact" title="Small icons">Compact</a></li> </ul></li> <li><a href="showlist.php?category=Popular" title="Themes downloaded the most over the last week."><strong>Popular</strong></a></li> </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.
Colin's take
One thing most people seem to be agreed on is that it is best to extract the HTML code from within the PHP code, as it becomes unmanagable after a while. The problem is then which templating engine to use... certainly the ones I have had a quick glance at on the list above, they tend to seem to work by passing them a data-structure (Array usually) which they can then do something with.
The "standard" seems to be Smarty, and I've taken a look at HTMLTMPL too and they seem to operate in the same way, it would be just a matter of deciding which was most suitable... I don't have an opinion on that, but I do think templating is the way to go.