Page 1 of 1

Creating a submenu conditional

Posted: Wed Mar 06, 2013 7:49 pm
by squarefrog
I have a main menu, and a sub menu. The submenu is called using:

Code: Select all

{menu start_level="2" template="foresight_submenu"}
so i ignore all level one menu items. The template code is as follows:

Code: Select all

{* Sub level navigation menu *} 

{if $count > 0}
  <ul class='sub_menu clearfix'>
    {foreach from=$nodelist item=node}
    {if $node->depth == 1}
        {if $node->current == true or $node->parent == true}
          <li class="active"><a href="{$node->url}">{$node->menutext}<span></span></a></li>
        {else}
          <li><a href="{$node->url}">{$node->menutext}<span></span></a></li>
        {/if}
      {/if}
    {/foreach}
  </ul>
{/if}
Now - I have one page that has no level 2 items, but in this instance I'd like to put a spacer div in. I've tried adding

Code: Select all

{else}
    <div class="spacer"></div>

at the bottom of my template, just before the {/if} statement. I expected the code to notice that $count == 0 and run my else statement, but this code isn't run at all.

It seems like if you call the menu with the start_level parameter then if $count == 0 then none of the code is run. Is there a way around this?

Re: Creating a submenu conditional

Posted: Wed Mar 06, 2013 8:21 pm
by squarefrog
I have just found out you can add {capture assign="var"} before your menu call and then evaluate it. Works perfect!

Found on http://edwardrobirds.com/dealing-with-e ... mple-cmsms.