PHPLIB templates can grant you an amazing ability to abstract the manipulation of data (in the database as well as in PHP) from its final format, whether that format is HTML, XML, WML, or a formatted e-mail, and some of these ways will be explored here.
It's not hard to nest blocks inside other blocks. Using this methodology, you can have a single template file that contains any number of logical template 'pages'. You just have to remember to start from the innermost loop first.
Take some HTML source:
three.ihtml
Contents of this book:
<UL>
<!-- BEGIN ChapterBlock -->
<LI> Chapter {chapter}
<OL>
<!-- BEGIN PageBlock -->
<LI> Page {page}
<!-- END PageBlock -->
</OL>
<!-- END ChapterBlock -->
</UL>
We start by defining the file
<?
$T->set_file('input_three', 'three.ihtml');
?>
And then we need to break out the blocks, starting with the innermost block.
It is VERY VERY IMPORTANT that you always start by setting the innermost block, and work out from there! Otherwise, you've removed the block in question, and the next block assignment won't work.
Notice that just before we parse the chapters (the '$j' loop) that we set the 'PBlock' variable to ''. That's because we use the template block more than once, and if we don't clean the slate, the values from the previous loop will remain.
To see this, just rem out this line and try the code again: