Re: IT[X] addBlock()

From: Date: Thu, 20 Dec 2001 10:18:36 +0000
Subject: Re: IT[X] addBlock()
References: 1 2  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-3559@lists.php.net to get a copy of this message
Alexander Merz wrote: > > > Furthermore I wonder up till now which IT[X] functions don't work yet? > > <cite author="ulf wendel"> > I should have never ever written ITX; I did so because it was simple to do > so. When you use addBlock & friends always keep in mind that these functions > stand > against the nature of IT. IT analyses the nesting of blocks to give you a > simple block api and make your code easy to understand. It was not made to > manipulate the nesting during runtime. Use e.g. phplib templates > (which are ++FastTemplate) for this. [...] This cite does not really answer the question. I'm just stating that IT[X] was not designed to manipulate the nesting of blocks during runtime. The main development goal was to provide a simple block API. I ended up with a template engine that analyses the block nesting structure of your template on it's own. If the template engine knows about the nesting of blocks, the API get's really simple. The only thing you have to care on (internal reason: recursion) is to parse the inner blocks of a block before you parse the outer block. Example: <table> <!-- BEGIN tr --> <tr> <!-- BEGIN td --> <td>{FIELD}</td> <td>{VALUE}</td> <!-- END td --> </tr> <!-- END tr --> </table> (you must parse td before parsing tr, but usually this anyway the order you collect the data in your application...) // PHPLib style $db->query("select * from products"); $it = new IntegratedTemplate(TPL_ROOT) $it->loadTemplatefile(TPL_FILE); while ($db->NextRecord()) { // you must start with the innermost block! $it->setCurrentBlock('inner_td_loop'); reset($db->Record); while (list($k => $v) = each($db->Record)) { $it->setVariable('FIELD', $k); $it->setVariable('VALUE', $v); $it->parseCurrentBlock(); } $it->setCurrentBlock('tr'); $it->parseCurrentBlock(); } Compare the example to the old, slow FastTemplates and PHPLib templates to get what I mean. IT is really simple. Smarty is the only engine who's (developers, not user) API is even simpler. But Smarty is something completly different to FastTemplates, PHPLib templates and IT[X]. Now, addBlock() & friends stand against the nature of IT. It was more or less simple to implement and I knew people would request it, that's why. I did some simple tests and it worked for me. Right before the last commits I got a bug report and - thanks! - a suggestion for a bug fix. addBlock() now works recursively and recognizes all blocks within the added block. And again, it worked for me. If it does not work for someone else: it's Open-Source, feel free to fix it. I don't have the time to care on all the source I've written in the past. My time is too short to do so and I can't do more but concentrate on the stuff I currently need at work, unless someone pays me for Open-Source development. To answer your question: all IT[X] functions passed my simple tests sucessfully. Ulf -- NetUSE AG Dr.-Hell-Straße Fon: +49 431 386 436 00 http://www.netuse.de/ D-24107 Kiel Fax: +49 431 386 435 99

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