Re: IT, or templates in general - another approach

From: Date: Tue, 21 May 2002 14:39:39 +0000
Subject: Re: IT, or templates in general - another approach
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-6283@lists.php.net to get a copy of this message
Wonderfully offtopic :) -- Personally I view The design of Simpletemplate is 'far superior to IT/IT[x] etc.' and I used it as a basis for my own little engine.. http://docs.akbkhome.com/PHPcodedoc/classes/Template_Engine.html http://docs.akbkhome.com/PHPcodedoc/classes/Filter_simpletags.html from a view 'up above' the two 'templating philosophies' appear to be ITX/IT/fasttemplate/phplib template = str_replace'ing at execution time smarty/simpletemplate/(my little hack of simpletemplate) = replacing templating with php code and executing that code at runtime. anyway, if you have a look at my derivative, you'll see a few diffences that would be nice to merge together - the xml/config stuff would be nice to extracted into a parent class - not part of the core engine. = doesnt look to difficult to do. - I can see the use of it, but most of the normal stuff doesnt need it. - In simpletemplate all the filters have to be loaded and have their methods registered and have to be instantated for each usage - the way I looked at it, each filter should be regarded as an driver/factory, once included (only if a compile is needed), all methods are included en mass., this way you just say I want filter package 'x', and it gets loaded only if the template needs generating (2-3 less includes per exectution) - you can also extend etc. the filters.... to suit your needs - like the rtf_simpletags... this is a code usage example - http://docs.akbkhome.com/PHPcodedoc/classes/PHP_CodeDoc.html#output_from_template The more I look at it, the more I like the Net_Curl idea of $curl = new Net_Curl $curl->url = "http://cccccc"; $curl->proxyusername = "...." $curl->execute(); rather than the setoptions concept.. $curl = new Net_Curl(array('url'=>'......','proxyusername'=>'....' etc. but both work anyway... the simpletags I devised did pretty much what smarty does - eg. {this.var.xxx} => maps to <?=htmlspecialchars($this->var->xxx)?> have a look at the filter for a more detailed list... or you could modify it to be a bit more xml friendly eg.<? echo .... ?> very easily by creating a xmlfriendly filter. It also copes with <a href="%5cthis.var.xxx%5d"> which is somthing that smarty failed on. - enabling editing of templates using mozilla's html editor.. etc. The indented html code was nice, but when you are using a wysiwyg editor, depending on html source layout is problematic. anyway - thanks wolfram, without your design+efforts, my little baby would be stillborn : regards alan ps. this was written after a few beers so pls excuse the 'lack of tact in some places'.... Wolfram Kriesing wrote:
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


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