How to count elements of submenu?

The place to talk about things that are related to CMS Made simple, but don't fit anywhere else.
Post Reply
dunn00
New Member
New Member
Posts: 2
Joined: Sat Jun 29, 2013 4:38 pm

How to count elements of submenu?

Post by dunn00 »

I'm showing the menu items like this

Code: Select all

{menu start_level ="3" number_of_levels="1" }
it has another submenu

Code: Select all

{menu start_level ="4" number_of_levels="1" }
with numbers of elements.

I want to put the number of menu items (from level 4) in brackets next to level 3 menu.

for example

Code: Select all

colors (3)
  - red
  - blue
  - white

shapes (4)
  - triangle
  - circle
  - square
  - diamond
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: How to count elements of submenu?

Post by velden »

Here an example of an altered Menu template which does that. You need to call it with 'number_of_levels=2'

Code: Select all

{* CSS classes used in this template:
.currentpage - The active/current page
.bullet_sectionheader - To style section header
hr.separator - To style the ruler for the separator *} 

{if $count > 0}
<ul id="mainmenu" class="clearfix">
{foreach from=$nodelist item=node}
{if $node->depth > $node->prevdepth}
{assign var="enteredsub" value=true}{assign var="subcount" value=0}
{elseif $node->depth < $node->prevdepth}
{assign var="enteredsub" value=false}({$subcount})</a></li>
{elseif $node->index > 0 && !$enteredsub}</a></li>
{/if}
{if $enteredsub}{assign var="subcount" value=$subcount+1}
{else}

{if $node->current == true}
<li{if $node->extra1 ne ""} class="{$node->extra1}"{/if}><a href="{$node->url}" class="currentpage"{if $node->target ne ""} target="{$node->target}"{/if}>{$node->menutext}

{elseif $node->parent == true && $node->depth == 1 and $node->type != 'sectionheader' and $node->type != 'separator'}
<li class="activeparent{if $node->extra1 ne ""} {$node->extra1}{/if}"> <a href="{$node->url}" class="activeparent"{if $node->target ne ""} target="{$node->target}"{/if}>{$node->menutext}

{elseif $node->type == 'sectionheader'}
<li class="sectionheader{if $node->extra1 ne ""} {$node->extra1}{/if}"><a>{$node->menutext}

{elseif $node->type == 'separator'}
<li style="list-style-type: none;"> <hr class="separator" />

{else}
<li{if $node->extra1 ne ""} class="{$node->extra1}"{/if}><a href="{$node->url}"{if $node->target ne ""} target="{$node->target}"{/if}>{$node->menutext}

{/if}
{/if}
{/foreach}
{if $enteredsub}({$subcount}){/if}</a></li>
</ul>
{/if}
It uses two extra variables:
enteredsub to determine if it is 'in the submenu' and subcount to count the submenu items.
This should give you an idea how to implement this in your situation. I'm not sure if this is the most efficient way.
dunn00
New Member
New Member
Posts: 2
Joined: Sat Jun 29, 2013 4:38 pm

Re: How to count elements of submenu?

Post by dunn00 »

thank you very much
User avatar
Rolf
Power Poster
Power Poster
Posts: 7825
Joined: Wed Apr 23, 2008 7:53 am
Contact:

Re: How to count elements of submenu?

Post by Rolf »

dunn00 wrote:thank you very much
Solved? Please http://forum.cmsmadesimple.org/viewtopi ... =7&t=22304
- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
Post Reply

Return to “The Lounge”