Page 1 of 1
[Pending] Menu Items
Posted: Thu Nov 04, 2010 2:30 pm
by Alain
Hello!
I've currently been editing some of the site and the menu isn't working as I intend(ed). Basically, the menu should behave like the following:
1.) The home item should have a background-image by default (default as in accessing the site, or clicking on home again);
2.) If a child (or child of child) is accessed, the 1st item ("most parent one") should be set as active, and thus, change background-colour to whatever colour;
3.) Home should not be clickable if you're there already.
Here's my site:
http://www.webzhopz.eu
Here's my menu code:
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}
{elseif $node->depth < $node->prevdepth}
{repeat string="</li></ul>" times=$node->prevdepth-$node->depth}
</li>
{elseif $node->index > 0}</li>
{/if}
{if $node->current == true && $node->depth == 1}
<li><a class="active" href="{$node->url}"><span>{$node->menutext}</span></a>
{elseif $page_alias == 'home'}
<li><a class="homeactive" href="{$node->url}"><span>{$node->menutext}</span></a>
{elseif $node->depth == 1}
<li><a href="{$node->url}"><span>{$node->menutext}</span></a>
{elseif $node->current == true && $node->depth != 1}
<li><a href="{$node->url}" {if $node->accesskey != ''} accesskey="{$node->accesskey}"{/if}{if $node->tabindex != ''} tabindex="{$node->tabindex}"{/if}{if $node->titleattribute != ''} title="{$node->titleattribute}"{/if}{if $node->target != ''} target="{$node->target}"{/if}><strong>{$node->menutext}</strong></a>
{elseif $node->type == 'sectionheader'}
<li>{$node->menutext}
{else}
<li><a href="{$node->url}"{if $node->accesskey != ''} accesskey="{$node->accesskey}"{/if}{if $node->tabindex != ''} tabindex="{$node->tabindex}"{/if}{if $node->titleattribute != ''} title="{$node->titleattribute}"{/if}{if $node->target != ''} target="{$node->target}"{/if}>{$node->menutext}</a>
{/if}
{/foreach}
{repeat string="</li></ul>" times=$node->depth-1}</li>
</ul>
{/if}
<br style="clear:left;" />
Any help would be greatly appreciated!
Re: Menu Items
Posted: Thu Nov 04, 2010 6:41 pm
by Dr.CSS
The menu you use is a drop down, the default for that is cssmenu.tpl which has most everything in it you need, only thing is currentpage is still a link, other default menus like simple_navigation will give the currentpage an h3, import cssmenu and make currentpage an h3 in it, just be caerful it may mess with second level current pages...
Re: [Solved] Menu Items
Posted: Mon Nov 08, 2010 10:27 am
by Alain
Hey,
I've fixed it by doing the following:
Code: Select all
{if $node->current == true && $node->depth == 1 && $node->alias != 'home'}
<li><a class="active" href="{$node->url}"><span>{$node->menutext}</span></a>
{elseif $node->alias == 'home' && $node->current == false}
<li><a class="home" href="{$node->url}"><span>{$node->menutext}</span></a>
{elseif $node->current == true && $node->alias == 'home'}
<li><a class="home-current" href="{$node->url}"><span>{$node->menutext}</span></a>
{elseif $node->depth == 1 && $node->alias != 'home'}
<li class="parent"><a href="{$node->url}"><span>{$node->menutext}</span></a>
{elseif $node->current == true && $node->depth != 1 && $node->alias != 'home'}
That sets the home anchor to class "home" when it's not the current page, and if it is, sets the anchor class to "home-current". Thanks for the help!
Re: [Pending] Menu Items
Posted: Tue Nov 09, 2010 8:21 am
by Alain
Hello again,
I tried to add multiple aliases using the same method as posted above, and ended up having this bit of code:
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}
{elseif $node->depth < $node->prevdepth}
{repeat string="</li></ul>" times=$node->prevdepth-$node->depth}
</li>
{elseif $node->index > 0}</li>
{/if}
{if $node->current == true && $node->depth == 1 && $node->alias != 'home' && $node->alias != 'organisatie' && $node->alias != 'webzhopz'}
<li><a class="active" href="{$node->url}"><span>{$node->menutext}</span></a>
{elseif $node->alias == 'home' && $node->current == false}
<li><a class="home" href="{$node->url}"><span>{$node->menutext}</span></a>
{elseif $node->current == true && $node->alias == 'home'}
<li><a class="home-current" href="{$node->url}"><span>{$node->menutext}</span></a>
{elseif $node->current = false && $node->alias == 'organisatie'}
<li><a class="organisatie" href="{$node->url}"><span>{$node->menutext}</span></a>
{elseif $node->current == true && $node->alias == 'organisatie'}
<li><a class="organisatie-current" href="{$node->url}"><span>{$node->menutext}</span></a>
{elseif $node->current = false && $node->alias == 'webzhopz'}
<li><a class="webzhopz" href="{$node->url}"><span>{$node->menutext}</span></a>
{elseif $node->current == true && $node->alias == 'webzhopz'}
<li><a class="webzhopz-current" href="{$node->url}"><span>{$node->menutext}</span></a>
{elseif $node->depth == 1 && $node->alias != 'home' && $node->alias != 'organisatie' && $node->alias != 'webzhopz'}
<li class="parent"><a href="{$node->url}"><span>{$node->menutext}</span></a>
{elseif $node->current == true && $node->depth != 1 && $node->alias != 'home' && $node->alias != 'organisatie' && $node->alias != 'webzhopz'}
<li><a href="{$node->url}" {if $node->accesskey != ''} accesskey="{$node->accesskey}"{/if}{if $node->tabindex != ''} tabindex="{$node->tabindex}"{/if}{if $node->titleattribute != ''} title="{$node->titleattribute}"{/if}{if $node->target != ''} target="{$node->target}"{/if}><strong>{$node->menutext}</strong></a>
{elseif $node->type == 'sectionheader'}
<li>{$node->menutext}
{else}
<li class="child"><a href="{$node->url}"{if $node->accesskey != ''} accesskey="{$node->accesskey}"{/if}{if $node->tabindex != ''} tabindex="{$node->tabindex}"{/if}{if $node->titleattribute != ''} title="{$node->titleattribute}"{/if}{if $node->target != ''} target="{$node->target}"{/if}>{$node->menutext}</a>
{/if}
{/foreach}
{repeat string="</li></ul>" times=$node->depth-1}</li>
</ul>
{/if}
<br style="clear:left;" />
However, that resulted in the following error:
string(140) "Smarty error: [in module_db_tpl:MenuManager;solidtheme line 18]: syntax error: unidentified token '=' (Smarty_Compiler.class.php, line 1410)" string(140) "Smarty error: [in module_db_tpl:MenuManager;solidtheme line 22]: syntax error: unidentified token '=' (Smarty_Compiler.class.php, line 1410)"
Any idea as to why this error would occur? I don't see any syntax errors unless I'm overlooking it.
Any help would be very appreciated.
Re: [Pending] Menu Items
Posted: Tue Nov 09, 2010 8:34 am
by uniqu3
Yes, you have 2 typos in there:
{if $count > 0}
{foreach from=$nodelist item=node}
{if $node->depth > $node->prevdepth}
{repeat string="" times=$node->depth-$node->prevdepth}
{elseif $node->depth prevdepth}
{repeat string="" times=$node->prevdepth-$node->depth}
{elseif $node->index > 0}
{/if}
{if $node->current == true && $node->depth == 1 && $node->alias != 'home' && $node->alias != 'organisatie' && $node->alias != 'webzhopz'}
url}">{$node->menutext}
{elseif $node->alias == 'home' && $node->current == false}
url}">{$node->menutext}
{elseif $node->current == true && $node->alias == 'home'}
url}">{$node->menutext}
{elseif $node->current == false && $node->alias == 'organisatie'}
url}">{$node->menutext}
{elseif $node->current == true && $node->alias == 'organisatie'}
url}">{$node->menutext}
{elseif $node->current == false && $node->alias == 'webzhopz'}
url}">{$node->menutext}
{elseif $node->current == true && $node->alias == 'webzhopz'}
url}">{$node->menutext}
{elseif $node->depth == 1 && $node->alias != 'home' && $node->alias != 'organisatie' && $node->alias != 'webzhopz'}
url}">{$node->menutext}
{elseif $node->current == true && $node->depth != 1 && $node->alias != 'home' && $node->alias != 'organisatie' && $node->alias != 'webzhopz'}
url}" {if $node->accesskey != ''} accesskey="{$node->accesskey}"{/if}{if $node->tabindex != ''} tabindex="{$node->tabindex}"{/if}{if $node->titleattribute != ''} title="{$node->titleattribute}"{/if}{if $node->target != ''} target="{$node->target}"{/if}>{$node->menutext}
{elseif $node->type == 'sectionheader'}
{$node->menutext}
{else}
url}"{if $node->accesskey != ''} accesskey="{$node->accesskey}"{/if}{if $node->tabindex != ''} tabindex="{$node->tabindex}"{/if}{if $node->titleattribute != ''} title="{$node->titleattribute}"{/if}{if $node->target != ''} target="{$node->target}"{/if}>{$node->menutext}
{/if}
{/foreach}
{repeat string="" times=$node->depth-1}
{/if}
Re: [Pending] Menu Items
Posted: Tue Nov 09, 2010 8:35 am
by Dr.CSS
Would you mind explaining why you need every page to have the page alias as a class?...
You could just add {$node->alias} to the class calls as it will auto add the pages alias wherever you put it, seems like you're going thru a lot of trouble to do something it will do automagicaly...
Re: [Pending] Menu Items
Posted: Tue Nov 09, 2010 8:40 am
by Alain
Thanks for the quick replies, guys.
The reason I do this is because I need three menu items (the parents) to have three different colours. For instance, home has to be yellow, whereas 'organisatie' (Organization) has to be red, and 'webzhopz' purple.
How would I achieve this using your method, granted that the exact result is possible?
Re: [Pending] Menu Items
Posted: Tue Nov 09, 2010 5:34 pm
by Dr.CSS
This will give every link li a class of the page alias, so you can target any one you want even if it's current or a parent or whatever, using the simple_navigation.tpl as a base, can be done to any of them...
{if $count > 0}
{foreach from=$nodelist item=node}
{if $node->depth > $node->prevdepth}
{repeat string="" times=$node->depth-$node->prevdepth}
{elseif $node->depth prevdepth}
{repeat string="" times=$node->prevdepth-$node->depth}
{elseif $node->index > 0}
{/if}
{if $node->parent == true or ($node->current == true and $node->haschildren == true)}
alais} menuactive menuparent">url}">{$node->menutext}
{elseif $node->haschildren == true and $node->type != 'sectionheader' and $node->type != 'separator'}
alias} parent">url}">{$node->menutext}
{elseif $node->current == true}
alias} currentpage">{$node->menutext}
{elseif $node->type == 'sectionheader'}
alais} sectionheader">{$node->menutext}
{elseif $node->type == 'separator'}
alais} separator" style="list-style-type: none;">
{else}
alais}">url}">{$node->menutext}
{/if}
{/foreach}
{repeat string="" times=$node->depth-1}
{/if}