Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.6.1

Bug #6759 Wrong replacement order of variables during parse()
Submitted: 2006-02-12 18:10 UTC
From: powerstat at web dot de Assigned:
Status: Wont fix Package: HTML_Template_PHPLIB (version CVS)
PHP Version: Irrelevant OS: All
Roadmaps: (Not assigned)    
Subscription  


 [2006-02-12 18:10 UTC] powerstat at web dot de
Description: ------------ When using the same template-variable within a page and a block thats contained by the page, then the behaviour during parsing the page might be different. Thats because inside the subst() method a loop runs over the list of known template variables. When a variable has been replaced before a block (that contains the same variable) will be replaced, then the variable will not be replaced within the block. When the block will be parsed first, then the variable will also be replaced within the block. Also the replace loop is a bootleneck, because some applications pollute te template class with a lot of variable settings that will often not been used when parsing a block. So it is much faster to extract the used variables from a block first and only replace the really used variables. Test script: --------------- test.php -------- <?php require_once('PHPLIB.php'); $templ = new Template_PHPLIB('.','keep'); $templ->setFile('page','test.html'); $templ->setVar('test0','000',false); $templ->setVar('test1','111',false); $templ->setBlock('page','blk_test3','blk_test3'); $templ->setVar('test2','222',false); echo $templ->parse('output','page',false); ?> test.html --------- <body> {test0} {test1} <!-- BEGIN blk_test3 --> abc {test1} def {test2} ghi <!-- END blk_test3 --> {test2} {test0} </body> A patch that fixes that and adds some other performance and code optimizations is available via email. Expected result: ---------------- <body> 000 111 abc {test1} def {test2} ghi 222 000 </body> Actual result: -------------- <body> 000 111 abc {test1} def 222 ghi 222 000 </body>

Comments

 [2006-02-17 20:59 UTC] powerstat at web dot de
 [2006-10-30 23:50 UTC] cweiske (Christian Weiske)
Your expected result implies that variables that are used in blocks and outside do never get replaced in the block. Further, this is original PHPLIB behavior and shouldn't be changed.
 [2006-10-31 06:32 UTC] powerstat at web dot de
It implies that variables within blocks require a separate parsing of this block. This is as all official demos of phplib demonstrate. So it is the correct behaviour. But better lets the original phplib developer decide ...