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

Need to close <div> tag within {foreach}

 
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
mifune
Smarty n00b


Joined: 16 Dec 2009
Posts: 2

PostPosted: Wed Dec 16, 2009 9:07 pm    Post subject: Need to close <div> tag within {foreach} Reply with quote

hello,

i have a little trouble generating a closing tag for a div within a foreach loop which runs on the following array:

Code:

Array
(
    [1,0] => Home
    [2,0] => Services
    [3,0] => Shop
    [3,1] => Gear
    [3,2] => Tools
    [3,3] => Utensils
    [3,4] => Gimmix
    [3,5] => Other
    [5,0] => Team
    [6,0] => Contact
    [6,1] => How to find us
)


i'm building a two level menu for navigation. the second level only appears if the according parent in the main menu is clicked.
basically every key with 0 ( [X,0] ) represents a main menu level. and every other [X,1], [X,2], [X,3], etc. represents a sub menu level.

here's my loop:

Code:

<div id="menu">
{foreach from=$menula key=k item=v}
   {if substr($k,2,2)==0}
      {if isset($smarty.get.m)}
         {if $k==$smarty.get.m}<i class="menu_clicked">{$v}</i><br />
         {else}<a href="{$k}.html" class="menu_titles">{$v}</a><br />{/if}
      {else}
         {if $k==1}<i class="menu_clicked">{$v}</i><br />
         {else}<a href="{$k}.html" class="menu_titles">{$v}</a><br />{/if}
      {/if}
   {elseif substr($k,0,1)==substr($smarty.get.m,0,1)}
      {if substr($k,2,2)==1}<div id="submenu">{/if}                <-- that's the div that needs closing
      {if substr($k,2,2)==substr($smarty.get.m,2,2)}
         <i class="menu_clicked">{$v}</i><br />
      {else} <a href="{$k}.html" class="menu_titles">{$v}</a><br />
      {/if}
      {closing div here?!}                                         <-- what'd be the condition for closing here?
   {/if}
{/foreach}
</div>



the div in red needs to be closed. but i have big difficulties specifying a condition, as i have trouble dealing with the variables, or the key of the array.

this is what the html code should ideally look like:
Code:

<div id="menu"><a href="1,0.html" class="menu_titles">Home</a><br />
  <a href="2,0.html" class="menu_titles">Services</a><br />
  <i class="menu_clicked">Shop</i><br />
  <div id="submenu">
     <a href="3,1.html" class="menu_titles">Gear</a><br />
    <a href="3,2.html" class="menu_titles">Tools</a><br />
    <a href="3,3.html" class="menu_titles">Utensils</a><br />
    <a href="3,4.html" class="menu_titles">Gimmix</a><br />
  </div>
  <a href="3,5.html" class="menu_titles">Other</a><br />
  <a href="5,0.html" class="menu_titles">Team</a><br />
  <a href="6,0.html" class="menu_titles">Contact</a><br />
</div>


anybody any ideas?
i would appreciate your feeback.
thanks!
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