PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » HTML » HTML_Template_PHPLIB » Bug #6759

Wrong replacement order of variables during parse()

Details

Submitted2006-02-12 18:10 UTC
Frompowerstat at web dot de
StatusWont fix
PackageHTML_Template_PHPLIB
PHP VersionIrrelevant
OSAll
Roadmaps(Not assigned)

Comments

[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>

[2006-02-17 20:59 UTC] powerstat at web dot de

Patch kann be found at:

http://www.hofmann-int.de/test/HTML_Template_PHPLIB.diff

[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 ...