Re: [Phplib-users] Template.inc
Brought to you by:
nhruby,
richardarcher
|
From: Layne W. <la...@if...> - 2001-09-26 15:36:46
|
> This solution is close to something I am Tring to figure out. The big
> difference is that in my case I am Tring to get it so that if there are
> no SUB_MENU entities the sub menu section is not displayed. From the
> way the example code works an empty SUB_MENU is produced even if there
> is no instance of the sub menu being generated. How would I work around
> this?
>
>> i need to use this kind of block in a template
>>
>> <!-- BEGIN MENU -->
>> <tr>
>> <td><a href="{NAME_MENU}"><img src="{IMG_MENU}"></a>
>> </tr>
>> <!-- BEGIN SUB_MENU -->
>> <tr>
>> <td><a href="{NAME_SUB_MENU}"><img src="{IMG_SUB_MENU}"></a>
>> </tr>
>> <!-- END SUB_MENU -->
>> <!--END MENU -->
>
> $tpl = new Template("../templates/");
> $tpl->set_file("example", "example.tpl");
> $tpl->set_block("example", "MENU");
> $tpl->set_block("MENU", "SUB_MENU", "SUB_MENUS");
>
> while( some loop that sets your variables ) {
> $tpl->set_var(array("NAME_SUB_MENU" => $name_sub_menu,
> "IMG_SUB_MENU" => $img_sub_menu));
> $tpl->parse("SUB_MENUS", "SUB_MENU", true);
> }
>
> $tpl->pparse("example", array("MENU"));
Add on the menu loop and clear out the sub-menu variable after each menu
loop.
$tpl = new Template("../templates/");
$tpl->set_file("example", "example.tpl");
$tpl->set_block("example", "MENU", "MENUS");
$tpl->set_block("MENU", "SUB_MENU", "SUB_MENUS");
while ( loop that pulls menu info ) {
$tpl->set_var(array("NAME_MENU" => $name_menu,
"IMG_MENU" => $img_menu));
while ( loop that pulls sub-menu info ) {
$tpl->set_var(array("NAME_SUB_MENU" => $name_sub_menu,
"IMG_SUB_MENU" => $img_sub_menu));
$tpl->parse("SUB_MENUS", "SUB_MENU", true);
}
$tpl->parse("MENUS", "MENU", true);
$tpl->set_var("SUB_MENUS", "");
}
Layne Weathers
Ifworld Inc
|