PEAR is archived and read-only

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

Home » HTML » HTML_Template_Sigma » Bug #939

Wrong replacement for omit variables

Details

Submitted2004-03-03 15:16 UTC
Fromreg at dav-muz dot net
StatusBogus
PackageHTML_Template_Sigma
PHP Version4.3.4
OSLinux Slackware9.1
Roadmaps(Not assigned)

Comments

[2004-03-03 15:16 UTC] reg at dav-muz dot net

Description:
------------
If I omit a variable created with "setVariable()" (than but it exists in an other block), Sigma rechecks and replace all the blocks that contain one variable with the same name in the same level (not in the sub-blocks).
This bug creates a new instance of the other (innocent) block!

Reproduce code:
---------------
In the file example.tpl
<!-- BEGIN dad -->
<b>{message}</b>
<!-- END dad -->
<!-- BEGIN mom -->
<b>Test:</b> <!-- the bug appear if I miss the variable "message" -->
<!-- END mom -->

In the file example.php
...
$tpl->setVariable('message', 'Hi, I\'m dad!<br />');
$tpl->parse('dad');
$tpl->setVariable('message', 'Hi, I\'m mom!<br />');
$tpl->parse('mom');
$tpl->show();
...

Expected result:
----------------
Hi, I'm dad

Actual result:
--------------
Hi, I'm dad!
Hi, I'm mom!

[2004-03-03 22:19 UTC] reg at dav-muz dot net

Sigma 1.0.2

I understand.
Well, why when I use {message} in "mom" block the "dad" block is parsed one time, and when I do not use {message} in "mom" block the "dad" block is parsed two times??? (In the second case the mom message do not appear in the dad block! Why? Is it a bogus??)

[reply]
If you want to prevent the specific block from appearing, use
hideBlock().
[/reply]

If I use this it can't hide only the second instance, but all!

Sorry if my english is not good. ^_^

[2004-04-02 13:26 UTC] lord_damokles at gmx dot net

The problem is that only used variables get cleared after parsing. The problem would be solved if the _variables array would be resetted after each parse().

It is true that hideBlock() would prevent the block from being shown, but if you have many blocks it is very inconvenient to hide all of them.
For example I have a template with 10 Blocks.
It contains a series of forms for some setup or so.
I use the same query everytime and use the returned ASSOC array in setVariable. Then I parse the desired block. If this block doesn't contain all variables of the query. The variables will be parsed into the first block which contains the placeholder.

Reproduce code:
---------------

<?php
//...
$tpl->setVariable (Array(
"var_block1_1" => "x",
"var_block1_2" => "y",
"var_block2_1" => "z"
));
$tpl->parse('block1');
print $tpl->get();
?>

[Template.tpl]

some text<br>
<!-- BEGIN block1 -->
Hallo {var_block1_1} Welt {var_block1_2} !!!<br>
<!-- END block1 -->
<!-- BEGIN block2 -->
should not be shown {var_block2_1} <br>
<!-- END block2 -->
another text

[/Template.tpl]

Expected result:
----------------
some text
Hallo x World y !!!
another text

Actual result:
--------------
some text
Hallo x World y !!!
should not be shown y
another text