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

Brian,

Thanks for your help!

> <!-- BEGIN chapterblock -->
> <!-- BEGIN pageblock -->
> <!-- END pageblock -->
> <!-- END chapterblock -->
>
> So i think you should code like this (this is what i always do):
>

Yeah, that's what I'm doing also - pull out the most nested one first, then
work out from there.

> I also dont understand:
>
> for ($page=$page; $page<=$chapter*3; $page++)
>
> because $page=$page will always just be true, nothing else.

I want to count from 1 to 9 in steps of three - So we start with $page being
whatever it is now, and add to it as $chapter escalates. For the purposes of
demonstration, this will produce chapter 1, page 1-3, chapter 2 page 4-6,
chapter 3, page 7-9.

You can't just pull that step out - it doesn't work, so you have to explicitly
say that $page = itself.

This behavior has been verified with echo statements.

> the final parsing:
>
> $t->parse("Output", "FileHandle", true);
>
> $t->p("Output");
>
> should be done like this;
>
> $t->parse("Output", "FileHandle");
>
> $t->p("Output");
>

Aren't these functionally the same? (true/false wouldn't make any difference
here because you are only parsing one example of the handle anyway, right?)

I'll be testing your sample code at the bottom to see if it fixes the problem
(hopefully) today - I have a MASSIVE number of axes in the fire right now!

The urgency on this has diminished a bit since I cheated and hard-coded some
HTML into the PHP code for the alpha release of the software, so I have a
*little* bit of time to figure this out before I have to "go live" with
anything.

Thanks SOOOO MUCH for your feedback!

-Ben

(PS: Wait'll you see the project - a collaborative "documentation engine" that
allows stuff like this to be cataloged, sorted, and made easy to find! - one of
the most exciting projects I've ever had anything to do with)

On Tue, 29 Aug 2000, you wrote:
> I dont know how to answer on the mailinglist, so i answer by email
>
> Is your problem with the nested block solved already?
>
> I see your blocks are nested like this:
>
> <!-- BEGIN chapterblock -->
> <!-- BEGIN pageblock -->
> <!-- END pageblock -->
> <!-- END chapterblock -->
>
> So i think you should code like this (this is what i always do):
>
> $t->set_file("FileHandle", $template_file);
> $t->set_block("FileHandle", "chapterblock", "cblock");
> $t->set_block("chapterblock", "pageblock", "pblock");
>
> and not:
>
> $t->set_file("FileHandle", $template_file);
> $t->set_block("FileHandle", "pageblock", "pblock");
> $t->set_block("FileHandle", "chapterblock", "cblock");
>
> because pageblock is inside chapterblock and not inside FileHandle.
> pageblocks are to be parsed inside pblock and pblock is a handle inside a
> chapterblock, right?
>
> I also dont understand:
>
> for ($page=$page; $page<=$chapter*3; $page++)
>
> because $page=$page will always just be true, nothing else.
>
> the final parsing:
>
> $t->parse("Output", "FileHandle", true);
>
> $t->p("Output");
>
> should be done like this;
>
> $t->parse("Output", "FileHandle");
>
> $t->p("Output");
>
> dont say 'true', because you will not add more FileHandles to Output, but
> insert only one.
>
> But the bigger problem is of course that you have too many pages in a
> chapter. this is because the pblock is not properly emptied and the
> beginning of the second for loop.
>
> try this code: (i didnt test it sorry)
>
> include "template.inc";
> $t=new template;
> $template_file="t.ihtml";
> $t->set_file("FileHandle", $template_file);
> $t->set_block("FileHandle", "chapterblock", "cblock");
> $t->set_block("chapterblock", "pageblock", "pblock"); //
> pageblock inside CHAPTERBLOCK
> $page=1;
> for ($chapter=1; $chapter<=3; $chapter++)
> {
> $t->set_var("page_id", $page++);
> $t->parse("pblock", "pageblock", false); // pblock will
> be reseted here and one pageblock SET INTO pblock
> $t->set_var("page_id", $page++);
> $t->parse("pblock", "pageblock", true); // APPEND
> another pageblock
> $t->set_var("page_id", $page++);
> $t->parse("pblock", "pageblock", true); // APPEND
> another
>
> $t->set_var("chapter_id", $chapter); // now the
> chapter
> $t->parse("cblock", "chapterblock", true); // parse
> chapterblock AFTER you parsed pblock!!
> }
>
> $t->pparse("Output", "FileHandle"); // shorter than parse and p,
> dont use 'true' for the parse,because you SET filehandle in output, you
> don't APPEND it
>
>
> Succes,
>
> Brian

-- 
Life is short. Live it!

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