nested blocks in templates
| From: | Erica Cirigliano | Date: | Sun, 24 Nov 2002 05:18:23 +0000 |
| Subject: | nested blocks in templates | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-11036@lists.php.net to get a copy of this message | ||
Hello,
I am learning HTML_Template_IT and I have a question about nesting blocks:
I want to display 3 product sections, each of which has a pricing table with several price points
within it. I am pulling display information for the sections as well as the pricing from a
database.
The problem is that the inner block for the pricing table executes only in the first loop through
the outer section block, so the first product section has pricing, but the successive sections do
not. Any suggestions on how to get the inner block to execute each time through the outer block?
TIA,
Erica
I have set up my html template like this:
...
<!-- BEGIN section -->
<tr><td ><a
name="{ANCHOR}">{ITEM}</a></div></td></tr>
<tr><td >
<table>
<tr><td>Quantity</td><td>Unit
Cost</td><td>Total</td></tr>
<!-- BEGIN row -->
<tr><td>{ITEMQTY}</td><td>${ITEMCOST}</td><td>${ITEMTOTAL}</td></tr>
<!-- END row -->
<tr><td>{ITEMLIMIT}</td><td>CALL US!</td><td>CALL
US!</td></tr>
</table>
</td></tr>
<!-- END section -->
...
and my script like this:
//start section block
while ($displayobj->fetchInto($sectionresult)) {
//loop through row block
while ($priceobj->fetchInto($priceresult)) {
//make sure to use row info related only to this section
if ($priceresult[0]==$sectionresult[0]) {
//assign values to row block
$tpl->setCurrentBlock("row");
$tpl->setVariable("ITEMQTY", $showqty);
$tpl->setVariable("ITEMCOST", $showsell);
$tpl->setVariable("ITEMTOTAL", $showtotal);
$tpl->parseCurrentBlock("row") ;
}
}
//assign values to section block
$tpl->setCurrentBlock("section");
$tpl->setVariable("ANCHOR", $sectionresult[1]);
$tpl->setVariable("ITEM", $sectionresult[2]);
$tpl->setVariable("ITEMLIMIT", $sectionresult[3]);
$tpl->parseCurrentBlock("section");
}
// print the output
$tpl->show();