[Phplib-users] Nested blocks in templates
Brought to you by:
nhruby,
richardarcher
|
From: Andrey L. <an...@nk...> - 2002-05-15 11:25:08
|
Hello,
Is there any possibility to create nested blocks using phplib's
templates? I'll try to explain what I mean by example:
Let's say we have such template (ttest.inc.html):
Page start
<hr>
<!-- BEGIN loop -->
<b>Loop begin: {LOOPNUM}</b>
<blockquote>
<!-- BEGIN subloop -->
subloop: {SUBLOOPNUM}<br>
<!-- END subloop -->
</blockquote>
<b>Loop end: {LOOPNUM}</b><hr>
<!-- END loop -->
Page end
and we want to produce output like:
Page start
Loop begin: 1
subloop: 1 - 1
subloop: 1 - 2
subloop: 1 - 3
subloop: 1 - 4
Loop end: 1
Loop begin: 2
subloop: 2 - 1
subloop: 2 - 2
subloop: 2 - 3
subloop: 2 - 4
Loop end: 2
Page end
so question is: how to do it? I was trying lot of tricks and this code
was closest, but it isn't what i nead...
<?php
require("prepend.inc.php");
$tpl = new Template(".");
$tpl->set_file("page", "ttest.inc.html");
$tpl->set_block("page", "loop", "litem");
for ($i=1; $i<=2; $i++) {
$tpl->set_var("LOOPNUM", $i);
$tpl->set_block("loop", "subloop", "slitem");
for ($j=1; $j<=4; $j++) {
$tpl->set_var("SUBLOOPNUM", "$i - $j");
$tpl->parse("slitem", "subloop", true);
}
$tpl->parse("litem", "loop", true);
}
$tpl->pparse("CONTENTS", "page");
?>
IMHO it must be very common and useful feature of templates, but i'm
starting to think that it's not possible... Maybe i'm missing
something?... please advice.
Thank you
--
Andrey Lebedev
Naujoji Komunikacija
|