Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Including a template in the same template

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
Karamfil
Smarty n00b


Joined: 25 Feb 2007
Posts: 4

PostPosted: Sun Feb 25, 2007 5:39 pm    Post subject: Including a template in the same template Reply with quote

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
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Mon Feb 26, 2007 3:49 pm    Post subject: Reply with 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.

Unrelatedly, have you considered {foreach} ? It tends to be easier to work with.
Back to top
View user's profile Send private message
Karamfil
Smarty n00b


Joined: 25 Feb 2007
Posts: 4

PostPosted: Tue Feb 27, 2007 2:38 pm    Post subject: Reply with quote

Hello Smile

Hmm {foreach} is harder for me Wink 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 Very Happy 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 Smile
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP