[phplib] templates - HELP ME PLEASE! From: Benjamin Smith (bens <email protected>)
Date: 08/29/00

I've nearly completed a rather large project using templates, and so far have
been rather pleased with them. It's a design goal to not use ANY HTML tags in
the PHP code, and but for this, I've been completely successful.

(thanks guys!)

But I can't seem to get template.inc to deal with nested-nested template
blocks!

EG:
        Block "A" # has inside it
                Block "B".

I can nest as many instances I need of block "B" inside of block "A". But when
I try to nest customized numbers of block "B" inside multiple, customized copies
of block "A", that's when the problem shows itself.

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:

Chapter1
        (page) 1
        (page) 2
        (page) 3
Chapter 2
        (page) 4
        (page) 5
        (page) 6
...

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

What I get instead is:

Chapter: 1
1
2
3
4
5
6
7
8
9

Chapter: 2
1
2
3

Chapter: 3
1
2
3
4
5
6

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-

##################

-Ben

-- 
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>

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