Help Menu Manager

The place to talk about things that are related to CMS Made simple, but don't fit anywhere else.
Locked
Regis
New Member
New Member
Posts: 4
Joined: Mon Nov 24, 2014 3:05 pm

Help Menu Manager

Post by Regis »

Hi. I'm running CMS Made Simple 1.10.3 - PHP 5.4.26 - MySQL 5.5.40 and Apache/2.2.26 (unix).

The module is Menu Manager 1.7.7
I can place a {menu} tag inside another template menu?
I know it sounds strange but a jquery plugin LiteTooltip use this submenu structure:

Code: Select all

<ul class="MENU">
  <li>
    <a href="javascript:void(0);" class="submenu" data-title='
      <div class="tooltip-menu">
        <ul>
          <li><a href="">Children 1</a></li>
          <li><a href="">Children 2</a></li>
          <li><a href="">Children 3</a></li>
        </ul>
      </div>
    '>PARENT MENU
    </a>
  </li>
</ul>
I was unable to change the template to fill the structure that the plugin asks, so I thought I'd leave the structure of the normal template and add another {menu} tag to bring the data to the submenu.

Code: Select all

<ul class="MENU">
  <li>
    <a href="javascript:void(0);" class="submenu" data-title='
      <div class="tooltip-menu">{menu template="submenu" start_level="2"}</div>
    '>PARENT MENU
    </a>
  </li>
</ul>
Works but the above code show the last children menutext on the parent menutext.

Code: Select all

<ul class="MENU">
  <li>
    <a href="javascript:void(0);" class="submenu" data-title='
      <div class="tooltip-menu">
        <ul>
          <li><a href="">Children 1</a></li>
          <li><a href="">Children 2</a></li>
          <li><a href="">Children 3</a></li>
        </ul>
      </div>
    '>Children 3  <---------- HERE MUST BE "PARENT MENU"
    </a>
  </li>
</ul>
Is there any parameter I should change when calling the submenu to operate without changing the parent MenuText?
Look a preview image:

Image

Thanks for any help.
Régis
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3484
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: Help Menu Manager

Post by velden »

I think when using a {menu} inside a menu template. The variables of the 'parent' menu template are overwritten by the 'child' menu template.
They are all in the same scope probably.

But, I think it can be done from within one menu template.
The logic to determine whether childs do exist is already there:

From Menu Manager Help:
$node->haschildren -- Returns true if this node has child nodes to be displayed

Code: Select all

 
Some incomplete, untested code:
{* check if we're "comming back" from childs to parent * }
{if $node->depth < $node->prevdepth && !empty($tmpNode)}
    {* finish the parent part of the menu *}
        </ul>
      </div>
    '>{$tmpNode->menutext}
    </a>
  </li>
     {* $tmpNode must be empty  *}
     {$tmpNode=null}
    {/if}

<li>
   {if $node->haschildren}
      {* save current node (=parent) to temporary variable for later use*}
      {$tmpNode=$node}
    <a href="javascript:void(0);" class="submenu" data-title='
      <div class="tooltip-menu">
        <ul>
    {/if}
...

Of course it needs some more checks etc. But you can look at the sample templates how that's done. 

Use number_of_levels param on menu tag to make sure it won't break your logic when an editor adds more levels than you count on.
    
Regis
New Member
New Member
Posts: 4
Joined: Mon Nov 24, 2014 3:05 pm

Re: Help Menu Manager

Post by Regis »

Hi Velden, thanks for the reply.
As the client was urgently, I found a partial solution... I created a new menu template to first level changing the $node->menutext by CGSimpleSmarty to get the text of the root menu. Once I have time to implement your code, I post the result here.

Here is my partial solution, if anyone needs.
In red where i changed.

Thanks
Régis
{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}
<ul class="main-navigation">
{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='current'}
{if $node->parent == true}
{assign var='classes' value='current menu parent submenu'}
{/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}" {if $node->children_exist == true}data-title='<div class="tooltip-menu">{menu template="simple_navigation.tpl" childrenof=$cgsimple->get_root_alias($node->alias) number_of_levels="1"}</div>'{/if}><span>{$cgsimple->get_root_alias($node->alias,'titulo')}{$cgsimple->get_page_menutext($titulo)}</span></a>

{elseif $node->children_exist == true and $node->type != 'sectionheader' and $node->type != 'separator'}
<li class="parent"><a href="{$node->url}" class="submenu parent" data-title='<div class="tooltip-menu">{menu template="simple_navigation.tpl" childrenof=$cgsimple->get_root_alias($node->alias) number_of_levels="1"}</div>'><span>{$cgsimple->get_root_alias($node->alias,'titulo')}{$cgsimple->get_page_menutext($titulo)}</span></a>

{elseif $node->current == true}
<li class="currentpage"><a href="{$node->url}" class="submenu currentpage" data-title='<div class="tooltip-menu">{menu template="simple_navigation.tpl" childrenof=$cgsimple->get_root_alias($node->alias) number_of_levels="1"}</div>'><span>{$cgsimple->get_root_alias($node->alias,'titulo')}{$cgsimple->get_page_menutext($titulo)}</span></a>

{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>
{/if}
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12709
Joined: Thu Mar 09, 2006 5:32 am
Location: Arizona

Re: Help Menu Manager

Post by Dr.CSS »

I'm not sure what you are trying to do from your explanations but I'm very sure you don't need all that {menu} stuff in a menu, I think it is going to make an awful lot of DB queries like that...
Locked

Return to “The Lounge”