IT, or templates in general - another approach

From: Date: Tue, 21 May 2002 13:52:56 +0000
Subject: IT, or templates in general - another approach
Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-6281@lists.php.net to get a copy of this message
i know this topic was on the list so often, but anyway :-) the current discussion on some issues in IT[X] just made me write this mail (again). may u just take it as an info (also regarding the current discussion on the IT-patch) i have written and already used successfully in a lot of projects a template class with another approach then IT[X] some catchy points: - no assigns in the php necessary (u can use any var in the tpl that is defined in php) - block building by indention (makes code cleaner too) - no template language to learn - compiling (and soon caching too) - easy to use for multilanguage sites, using PEAR::I18N see example, below - each tpl is configurable individually via XML tags or file(s) project homepage is http://sf.net/projects/simpletpl docs and example is at: http://wolfram.kriesing.de/libs/php/SimpleTemplate/examples/fullFeatured a short example to show how the template class works: ******* php file ******** <?php $aVar = 'some text to show in the tpl'; $anArray = array( 'one' , 'two' , 'three' ); // the $tpl needs to be instanciated somewhere above // for easier reading this is left out here $tpl->compile( 'tpl-filename.tpl' ); include( $tpl->getCompiledTemplate() ) ?> ******** tpl-file ********* print out the text: {$aVar} loop through $anArray {if(sizeof($anArray)<10)} {foreach( $anArray as $key=>$val )}
       {$key} =&gt; {$val}
       <br>
******* or a configured template file ****** <!-- configure, set different delimiter --> <SimpleTemplate>
|    <delimiter begin="[[" end="]]"/>
|</SimpleTemplate> print out the text: [[$aVar]] loop through $anArray [[foreach( $anArray as $aVal )]] [[$aVal]]<br> ******* or another configured template file, with caching ****** <SimpleTemplate>
|    <delimiter begin="[[" end="]]"/>
<cache>
       <!-- cache the final output for 10 minutes -->
       <time value="10" units="minutes">
||        <!-- and make it depend on the given vars -->
||        <depends value="$_REQUEST $myVar $someVar">
</cache> |</SimpleTemplate> print out the text: [[$aVar]] loop through $anArray [[foreach( $anArray as $aVal )]] [[$aVal]]<br> ********************** caching is not in the CVS yet, but this week it will be going there the entire xml-string can also be inside an xml-file, which resides in the same directory or on the path to the file and it will be used too. this way you can configure all files in a directory by writing simply one xml-file containing the config. see for example http://wolfram.kriesing.de/libs/php/SimpleTemplate/examples/xmlConfig/ if there is no interest on this for PEAR i would still be interested in opinions and suggestions -- Wolfram ... translating template engine .... http://sf.net/projects/simpletpl ... authentication system .... http://sf.net/projects/auth

« previous php.pear.dev (#6281) next »