[Solved] Basic Horizontal Menu with Selected Menu Items

The place to talk about things that are related to CMS Made simple, but don't fit anywhere else.
Post Reply
apollo9
Forum Members
Forum Members
Posts: 22
Joined: Sat Nov 09, 2013 3:10 pm

[Solved] Basic Horizontal Menu with Selected Menu Items

Post by apollo9 »

I've been trying to reinstate a very basic horizontal menu at the top of our website containing selected menu items, some parent, some child.
It needs to be displayed in one line, with the same styling.

Currently, the menu displays inline - but parent items are on the top line, child items are on the line below and styled as per li li.

Here's the site with menu as described. http://cornworthy.com.gridhosted.co.uk/cms/

I'm calling the menu as such

Code: Select all

{menu template='corn2_menu_header' number_of_levels='1' items='home,events-activities,website-contacts,gardeners-world,search-your-ancestors'}
The menu template copied from another menu:

Code: Select all

{assign var='number_of_levels' value=10000}
{if isset($menuparams.number_of_levels)}
  {assign var='number_of_levels' value=$menuparams.number_of_levels}
{/if}

{if $count > 0}
<div id="corn2_menu_header">

<ul>
{foreach from=$nodelist item=node}
{if $node->depth > $node->prevdepth}
{repeat string="<ul>" times=$node->depth-$node->prevdepth}
{elseif $node->depth < $node->prevdepth}
{repeat string="</li></ul>" times=$node->prevdepth-$node->depth}
</li>
{elseif $node->index > 0}</li>
{/if}

{if $node->parent == true or $node->current == true}
  {assign var='classes' value='selected'}
  {if $node->parent == true}
    {assign var='classes' value='selectedparent'}
  {/if}
  {if $node->children_exist == true and $node->depth < $number_of_levels}
    {assign var='classes' value=$classes|cat:' parent'}
  {/if}
  <li class="{$classes}"><a class="{$classes}" href="{$node->url}"><span>{$node->menutext}</span></a>

{elseif $node->children_exist == true and $node->depth < $number_of_levels and $node->type != 'sectionheader' and $node->type != 'separator'}
<li class="parent"><a class="parent" href="{$node->url}"><span>{$node->menutext}</span></a>

{elseif $node->current == true}
<li class="currentpage"><h3><span>{$node->menutext}</span></h3>

{elseif $node->type == 'sectionheader'}
<li class="sectionheader"><span>{$node->menutext}</span>

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

{else}
<li><a href="{$node->url}"><span>{$node->menutext}</span></a>

{/if}

{/foreach}
{repeat string="</li></ul>" times=$node->depth-1}</li>
</ul>
</div>
{/if}
Hope someone can provide some ideas. Expect I'm missing something obvious!

Chris
Last edited by apollo9 on Fri Apr 17, 2015 1:35 pm, edited 1 time in total.
User avatar
paulbaker
Dev Team Member
Dev Team Member
Posts: 1465
Joined: Sat Apr 18, 2009 10:09 pm
Contact:

Re: Basic Horizontal Menu with Selected Menu Items

Post by paulbaker »

Too many <ul>s.

Try changing

Code: Select all

{repeat string="<ul>" times=$node->depth-$node->prevdepth}
in to

Code: Select all

{* repeat string="<ul>" times=$node->depth-$node->prevdepth *}
(i.e. comment it out)
To copy System Information to the forum:
https://docs.cmsmadesimple.org/troubles ... nformation

CMS Made Simple Geekmoots attended:
Nottingham, UK 2012 | Ghent, Belgium 2015 | Leicester, UK 2016
apollo9
Forum Members
Forum Members
Posts: 22
Joined: Sat Nov 09, 2013 3:10 pm

Re: Basic Horizontal Menu with Selected Menu Items

Post by apollo9 »

Excellent! Thank you!
Post Reply

Return to “The Lounge”