[phplib] nested templates - what am I doing wrong? From: Benjamin Smith (bens <email protected>)
Date: 08/26/00

I can't seem to get template.inc to deal with nested templates!

RH 6.2, Apache 1.3.12, PHP 4.0.1pl2.

Attached, please find files t.ihtml (the template), t.php (the file using the
template function) and results.html (what the result is).

I'm trying to nest one block inside another, for use in a chapter/page
scenario:

Chapter 1
        page 1
        page 2
        page 3
Chapter 2
        page 4
        page 5
        page 6

I've created this very simple code to demonstrate the problem that I'm having.

What am I doing wrong? I'm using 7.2c PHPLIB...

In case this list does not support attachments, I'm including the full text of
these files here:

####################### php file (t.php)
<?php

/*

Goal.

Chapter X
        page 1
        page 2
        page 3
Chapter Y
        page 4
        page 5
        page 6
Chapter Z
        page 7
        page 8
        page 9

*/

### Variables:

include "template.inc";

$t=new template;

$template_file="t.ihtml";

$t->set_file("FileHandle", $template_file);

$t->set_block("FileHandle", "pageblock", "pblock");

$t->set_block("FileHandle", "chapterblock", "cblock");

$page=1;

for ($chapter=1; $chapter<=3; $chapter++)
        {
        $t->set_var("chapter_id", $chapter);
        $t->parse("cblock", "chapterblock", true);
        for ($page=$page; $page<=$chapter*3; $page++)
                {
                $t->set_var("page_id", $page);
                $t->parse("pblock", "pageblock", true);
                }

        }

$t->parse("Output", "FileHandle", true);

$t->p("Output");

?>

################### Template File (t.ihtml)

<UL>

-top-

<!-- BEGIN chapterblock -->

<LI>Chapter: {chapter_id}<BR>
<UL>

<!-- BEGIN pageblock -->
<LI>{page_id}<BR>
<!-- END pageblock -->

</UL>
<!-- END chapterblock -->
</UL>

-bot-

################## Results (results.html)

<UL>

-top-

<LI>Chapter: 1<BR>
<UL>

<LI>1<BR>
<LI>2<BR>
<LI>3<BR>
<LI>4<BR>
<LI>5<BR>
<LI>6<BR>
<LI>7<BR>
<LI>8<BR>
<LI>9<BR>

</UL>

<LI>Chapter: 2<BR>
<UL>

<LI>1<BR>
<LI>2<BR>
<LI>3<BR>

</UL>

<LI>Chapter: 3<BR>
<UL>

<LI>1<BR>
<LI>2<BR>
<LI>3<BR>
<LI>4<BR>
<LI>5<BR>
<LI>6<BR>

</UL>
</UL>

-bot-

-- 
Life is short. Live it!

  • text/x-c attachment: t.php

--------------------------------------------------------------------- To unsubscribe, e-mail: phplib-unsubscribe <email protected> For additional commands, e-mail: phplib-help <email protected>