Re: [Phplib-users] Nested blocks in templates
Brought to you by:
nhruby,
richardarcher
|
From: Richard A. <rh...@ju...> - 2002-05-15 12:22:09
|
At 1:24 PM +0200 15/5/02, Andrey Lebedev wrote:
>Is there any possibility to create nested blocks using phplib's
>templates? I'll try to explain what I mean by example:
Here's a sample I've posted to the list before. Almost what you want.
Template:
<HTML>
<BODY>
<PRE>
<!-- BEGIN GROUP -->
{GROUPNAME}
<!-- BEGIN CELL -->
{CELLVALUE} : {CELLVALUE2}
<!-- END CELL -->
<!-- END GROUP -->
</PRE>
</BODY>
</HTML>
Script:
<?php
include("template.inc");
# create Template instance called $t
$t = new Template(".","comment");
$t->debug=true;
# define variables named page and box, referencing files
$t->set_file(array("test" => "nesttest.tmpl"));
# extract the block named "GROUP" from "test", creating a
# reference to {group} in "test".
$t->set_block("test", "GROUP", "group");
# extract the block named "CELL" from "GROUP", creating a
# reference to {cell} in "GROUP".
$t->set_block("GROUP", "CELL", "cell");
for ($i=1; $i<=3; $i++) {
$t->set_var("cell", "");
for ($j=1; $j<=3; $j++) {
$t->set_var(array("CELLVALUE" => $j, "CELLVALUE2" => $j*10));
$t->parse("cell", "CELL", true);
}
$t->set_var(array("GROUPNAME" => $i));
$t->parse("group", "GROUP", true);
}
# build out from test...
$t->pparse("out", "test");
unset($t);
?>
Output:
1
1 : 10
2 : 20
3 : 30
2
1 : 10
2 : 20
3 : 30
3
1 : 10
2 : 20
3 : 30
...R.
|