Page 1 of 1

[solved] - Menu template question

Posted: Mon Apr 11, 2011 7:30 pm
by naturelab
Could anyone help me out with this ?

I am trying to specify one section ( alias ) and prevent the menu from displaying ONLY it's child elements, but display child elements of other sections. Like this :-

== SHOW THIS ==<ul>
== SHOW THIS ==<li>anotherSection</li>
== SHOW THIS ==<ul>
== SHOW THIS ==<li>anotherSection child 1</li>
== SHOW THIS ==<li>anotherSection child 2</li>
== SHOW THIS ==<li>anotherSection child 3</li>
== SHOW THIS ==<li>anotherSection child 4</li>
== SHOW THIS ==<ul>

== SHOW THIS ==<li>mySection</li>

== BUT EXCLUDE THIS ==<ul>
== BUT EXCLUDE THIS ==<li>mySection child 1</li>
== BUT EXCLUDE THIS ==<li>mySection child 2</li>
== BUT EXCLUDE THIS ==<li>mySection child 3</li>
== BUT EXCLUDE THIS ==<li>mySection child 4</li>
== BUT EXCLUDE THIS ==</ul>

== SHOW THIS ==</ul>



ie :- in the template

Code: Select all

{if $count > 0}
<ul>
{foreach from=$nodelist item=node}

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

{if $node->alias == "mySection"}
AT THIS LEVEL DO NOT DISPLAY ITS CHILDREN ie :-
{/if}


{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='menuactive'}
  {if $node->parent == true}
    {assign var='classes' value='menuactive menuparent'}
  {/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>
{/if}


Any help greatly appreciated. Thanks

Re: Menu template question

Posted: Mon Apr 11, 2011 9:57 pm
by Dr.CSS
You don't want it to show in the menu but do you care if it shows in the page source?...

Re: Menu template question

Posted: Mon Apr 11, 2011 10:06 pm
by naturelab
Hi - Yes,correct. I DON'T want to show it in the page source.

( I had previously been hiding it with Jquery / css ).

Since posting, I've been trying to identify the child elements by using {$node->hierarchy}, which will always be constant on this site :-

Something like :-

Code: Select all

{if $node->hierarchy > 6  && $node->hierarchy < 7}
{assign var='hide' value=1}
{/if}
But I'm not quite there yet. Its removing the child elements, but I'm still getting a load of empty <li></li>'s and <ul>'s

[SOLVED] Re: Menu template question

Posted: Tue Apr 12, 2011 3:15 pm
by naturelab
OK. Managed to solve by doing this. Might seem a bit messy, but it works.

Code: Select all

{if $count > 0}

<ul id="jsddm">
{foreach from=$nodelist item=node}
{if $node->depth > $node->prevdepth && !($node->hierarchy > 6  && $node->hierarchy < 7)}
{repeat string="<ul>" times=$node->depth-$node->prevdepth}
{elseif $node->depth < $node->prevdepth}
{if !($node->hierarchy == 8)}{repeat string="</li></ul>" times=$node->prevdepth-$node->depth}{/if}
</li>
{elseif $node->index > 0 && !($node->hierarchy > 6  && $node->hierarchy < 7)}
</li>
{/if}

{if $node->type == 'sectionheader' and $node->parent == true or ($node->current == true and $node->haschildren == true)}
<li id="{$node->alias}" class="active menuparent"><a href="{$node->url}" title="{$node->menutext} Section"  {if $count == ($node->index+1)} class="last"{/if}>{$node->menutext}</a>

{elseif $node->parent == true or ($node->current == true and $node->haschildren == true)}
<li id="{$node->alias}" class="active menuparent"><a href="{$node->url}" title="Link : {$node->menutext} : accesskey={$node->accesskey}" accesskey="{$node->accesskey}" {if $count == ($node->index+1)} class="last"{/if}>{$node->menutext}</a>

{elseif $node->haschildren == true and $node->type != 'sectionheader' and $node->type != 'separator'}
<li id="{$node->alias}" class="parent"><a class="parent" href="{$node->url}" title="Link : {$node->menutext} : accesskey={$node->accesskey}" accesskey="{$node->accesskey}" {if $count == ($node->index+1)} class="last"{/if}>{$node->menutext}</a>

{elseif $node->current == true}

<li id="{$node->alias}" class="active"><a href="{$node->url}" title="Link : {$node->menutext} : accesskey={$node->accesskey}" accesskey="{$node->accesskey}" {if $count == ($node->index+1)} class="last"{/if}>{$node->menutext}</a>

{elseif $node->type == 'sectionheader'}
<li id="{$node->alias}" class="sectionheader"><a href="#" title="{$node->menutext} Section"  {if $count == ($node->index+1)} class="last"{/if}>{$node->menutext}</a>

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

{else}

{if $node->hierarchy > 6  && $node->hierarchy < 7}

{else}

<li id="{$node->alias}"><a href="{$node->url}" title="Link : {$node->menutext} : accesskey={$node->accesskey}" accesskey="{$node->accesskey}" {if $count == ($node->index+1)} class="last"{/if}>{$node->menutext}</a>
{/if}
{/if}

{/foreach}

{repeat string="</li></ul>" times=$node->depth-1}</li>
</ul>
{/if}


Re: Menu template question

Posted: Thu Apr 14, 2011 11:46 am
by naturelab
I guess what I'm asking for is :-

Code: Select all

excludechildrenof="" -
similar to these...

Code: Select all

# (optional) excludeprefix="" - Exclude all items (and their children) who's page alias matches one of the specified (comma separated) prefixes. This parameter must not be used in conjunction with the includeprefix parameter.
# (optional) includeprefix="" - Include only those items who's page alias matches one of the specified (comma separated) prefixes. This parameter cannot be combined with the excludeprefix parameter.
# (optional) childrenof="" - This option will have the menu only display items that are descendants of the selected page id or alias. i.e: {menu childrenof=$page_alias} will only display the children of the current page.