Creating a submenu conditional

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Post Reply
squarefrog
New Member
New Member
Posts: 6
Joined: Fri Apr 23, 2010 9:20 am

Creating a submenu conditional

Post 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?
squarefrog
New Member
New Member
Posts: 6
Joined: Fri Apr 23, 2010 9:20 am

Re: Creating a submenu conditional

Post 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.
Post Reply

Return to “CMSMS Core”