|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
Karamfil Smarty n00b
Joined: 25 Feb 2007 Posts: 4
|
Posted: Sun Feb 25, 2007 5:39 pm Post subject: Including a template in the same template |
|
|
Hello,
I have a section and I need to include the same template as current. here is the code:
the PHP
Code: | $submenuItem1 = array("link" => "###1", "title" => "submlink1", "submenu" => "no", "sub" => "");
$submenuItem2 = array("link" => "###2", "title" => "submlink2", "submenu" => "no", "sub" => "");
$submenuItem3 = array("link" => "###3", "title" => "submlink3", "submenu" => "no", "sub" => "");
$submenuItem4 = array("link" => "###4", "title" => "submlink4", "submenu" => "no", "sub" => "");
$menuItem1 = array("link" => "###1", "title" => "mlink1", "submenu" => "no", "sub" => "");
$menuItem2 = array("link" => "###2", "title" => "mlink2", "submenu" => "yes", "sub" => array($submenuItem1, $submenuItem2, $submenuItem3, $submenuItem4~));
$menuItem3 = array("link" => "###3", "title" => "mlink3", "submenu" => "no", "sub" => "");
$menuItem4 = array("link" => "###4", "title" => "mlink4", "submenu" => "no", "sub" => "");
$tpl->assign("menu", array ($menuItem1, $menuItem2, $menuItem3, $menuItem4)); |
sub.tpl
Code: |
<ul>
{section name=subid loop=$items}
<li><a href="{$items[subid].link}">{$items[subid].title}</a>
{if $items[subid].submenu == 'yes'}
{include file="sub.tpl" items=$items[subid].sub }
{/if}
</li>
{/section}
</ul>
|
It is doing the second section loop and after that it stops and not showing the other last two elements.
Does anybody know how can I fix this? |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Mon Feb 26, 2007 3:49 pm Post subject: |
|
|
Does it still happen if you use a different include variable name (other than $items) ? It shouldn't make a difference I'm just curious.
Unrelatedly, have you considered {foreach} ? It tends to be easier to work with. |
|
Back to top |
|
Karamfil Smarty n00b
Joined: 25 Feb 2007 Posts: 4
|
Posted: Tue Feb 27, 2007 2:38 pm Post subject: |
|
|
Hello
Hmm {foreach} is harder for me i tried it
here is the code
Code: | {foreach item=menuItem from=$menu}
<li><a href="{$menuItem.link}">{$menuItem.title}</a>
{if $menuItem.submenu == 'yes'}
<ul>
{include file="sub.tpl" menu=$menuItem.sub }
</ul>
{/if}
</li>
{/foreach}
|
Yeah working Thaaaaaanks \o/
Quote: | Does it still happen if you use a different include variable name (other than $items) ? It shouldn't make a difference I'm just curious.
|
Hmm not sure but i think I can't use diferent variable, since I'm including the same file |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|