Page 1 of 1

[SOLVED] Problem with generated menu Code

Posted: Wed Jun 11, 2008 7:24 am
by force2083
I'm using CMS Made Simple 1.3 "Cuba" (but had this Problem with other versions too)

There are some problems with the menu...

I add following code to the template:

Code: Select all

<!-- start menu -->
<div id="navigation">
<ul>
{menu template='Layout01' number_of_levels='1'}
</ul>
</div>
<!-- end menu -->
and the menu template looks like this:

Code: Select all

 {if $count > 0}
{foreach from=$nodelist item=node}
 <li><a href="{$node->url}" title="{$node->titleattribute}" {if $node->target ne ""} target="{$node->target}"{/if}>{$node->menutext}</a>
{if $count > ($node->index+1)} </li>
{/if}
{/foreach}
{/if}
the expected output should look like this:

Code: Select all

<!-- start menu -->
<div id="navigation">
<ul>
  <li><a href="http://www.url.de/cmsms/" title="Home Page, shortcut key=1" >Home</a>
  </li>
  <li><a href="http://www.url.de/cmsms/index.php?page=link1" title="" >Link1</a>
  </li>
  <li><a href="http://www.url.de/cmsms/index.php?page=link2" title="" >Link2</a>
  </li>
  <li><a href="http://www.url.de/cmsms/index.php?page=link3" title="" >Link3</a>
  </li>
  <li><a href="http://www.url.de/cmsms/index.php?page=link4" title="" >Link4</a>
  </li>
  <li><a href="http://www.url.de/cmsms/index.php?page=link5" title="" >Link5</a>
  </li>
</ul>
</div>
<!-- end menu -->
but the real output forget the last -tag
did I do something wrong or is this a bug?

Dirk

Re: Problem with generated menu Code

Posted: Wed Jun 11, 2008 7:52 am
by rvdv
Don't think it's a bug. I checked it on a test setup and i have 10 menu items. My $count var shows me 10 like it should. But the $node->index starts with 0. This means that the last $node->index+1 is the same as your $count.

At the moment you're checking if $count is higher then $node->index+1 but it should be equal to or higher then. So your menu should be:

Code: Select all

{if $count > 0}
	{foreach from=$nodelist item=node}
		<li><a href="{$node->url}" title="{$node->titleattribute}" {if $node->target ne ""} target="{$node->target}"{/if}>{$node->menutext}</a>
		{if $count >= $node->index+1} 
			</li>
		{/if}
	{/foreach}
{/if}
Good luck ;)

Re: Problem with generated menu Code

Posted: Wed Jun 11, 2008 8:02 am
by force2083
Oh man... what a small sign can do.  :D
Thanks a lot.

But if i remember it right this was a default Menu Example (included in the standard installation), maybe it should be changed there too???

Re: [SOLVED] Problem with generated menu Code

Posted: Wed Jun 11, 2008 8:04 am
by Dr.CSS
I've seen every menu template for the last 2 plus years and none of them had index+1... iirc...

Re: [SOLVED] Problem with generated menu Code

Posted: Wed Jun 11, 2008 8:13 am
by rvdv
mark wrote: I've seen every menu template for the last 2 plus years and none of them had index+1... iirc...
Then check again... It's the 'simple_menu' on this page. :)

Re: [SOLVED] Problem with generated menu Code

Posted: Wed Jun 11, 2008 8:53 am
by force2083
Ok if I understand it right, it's enough to use this code and leave the 2nd if clause

Code: Select all

{if $count > 0}
 {foreach from=$nodelist item=node}
  <li><a href="{$node->url}" title="{$node->titleattribute}" {if $node->target ne ""} target="{$node->target}"{/if}>{$node->menutext}</a></li>
 {/foreach}
{/if}

Re: [SOLVED] Problem with generated menu Code

Posted: Wed Jun 11, 2008 9:10 am
by rvdv
Yes, in the simple menu they use that if so the menu doesn't shows a | after the last menu item.