How to add specified css class for every page in menu? Topic is solved

General project discussion. NOT for help questions.
Post Reply
Cody

How to add specified css class for every page in menu?

Post by Cody »

Hello,
do you know, please, how is possible to have every page specific CSS classs?

For example structure of the pages could be:

1. úvod
2. text
3. závěr

what represents HTML code:

Code: Select all

<ul>
<li><a href="#">úvod</a></li>
<li><a href="#">text</a></li>
<li><a href="#">závěr</a></li>
</ul>
...and I need something similar...

Code: Select all

<ul>
<li class="uvod"><a href="#">úvod</a></li>
<li class="text"><a href="#">text</a></li>
<li class="zaver"><a href="#">závěr</a></li>
</ul>
I tried to use class="{$node.alias}", but id doesnt work. When I put into the menu 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}
{elseif $node->depth < $node->prevdepth}
{repeat string="</li></ul>" times=$node->prevdepth-$node->depth}
</li>
{elseif $node->index > 0}</li>
{/if}

{elseif $node->current == true}
<li class="{$node.alias}" id="active">{$node->menutext}

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

{/if}

{/foreach}
{repeat string="</li></ul>" times=$node->depth-1}</li>
</ul>
{/if}
The CMS write this error:
string(136) "Smarty error: [in module_db_tpl:MenuManager;navigation line 12]: syntax error: unexpected {elseif} (Smarty_Compiler.class.php, line 486)"
string(134) "Smarty error: [in module_db_tpl:MenuManager;navigation line 15]: syntax error: unexpected {else} (Smarty_Compiler.class.php, line 478)"
string(176) "Smarty error: [in module_db_tpl:MenuManager;navigation line 18]: syntax error: mismatched tag {/if}. expected {/foreach} (opened line 3). (Smarty_Compiler.class.php, line 2303)"
string(176) "Smarty error: [in module_db_tpl:MenuManager;navigation line 20]: syntax error: mismatched tag {/foreach}. expected {/if} (opened line 1). (Smarty_Compiler.class.php, line 2303)"
string(139) "Smarty error: [in module_db_tpl:MenuManager;navigation line 23]: syntax error: mismatched tag {/if}. (Smarty_Compiler.class.php, line 2303)"
Parse error:  syntax error, unexpected T_ELSEIF in /data/www/beznudy.cz/test.beznudy.cz/tmp/templates_c/8e95733b1edd65963770a93603b5efcb^%%D4^D49^D49AE758%%module_db_tpl%3AMenuManager%3Bnavigation.php on line 20
Can anybody helps me? Have I some bug in my template? Or the method is wrong? How shold I put specified css class in the menu?

I use last CMS MS 1.6.6 ib Czech language, on Apache server (Linux 2.6.18-6-amd64 Zap x86_64), Php 5.2.12, MySQL 5.0.32 .
Last edited by Cody on Sat Jan 23, 2010 11:46 am, edited 1 time in total.
ironblaze94

Re: How to add specified css class for every page in menu?

Post by ironblaze94 »

First of all you are getting an ELSE error because you are starting with an ELSEIF instead of IF like so:

{elseif $node->current == true}
{$node->menutext}

{else}
url}">{$node->menutext}

Second of all, calling elements from the node looks like {$node->menutext} NOT {$node.alias}

Try {$node->alias} instead
Cody

Re: How to add specified css class for every page in menu?

Post by Cody »

No I am trzing some things, template is this:

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}
<li class="{$node.alias}" title="{$node->menutext}"> {$node->menutext}

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

{/if}

{/foreach}
{repeat string="</li></ul>" times=$node->depth-1}</li>
</ul>
{/if}
..and error is this>Fatal error: Cannot use object of type stdClass as array in /data/www/beznudy.cz/test.beznudy.cz/tmp/templates_c/8e95733b1edd65963770a93603b5efcb^%%EB^EB7^EB77B4F0%%module_db_tpl%3AMenuManager%3Bmenu-modryhad.php  on line 21
minneapolisite
Forum Members
Forum Members
Posts: 24
Joined: Sat Feb 23, 2008 1:15 pm

Re: How to add specified css class for every page in menu?

Post by minneapolisite »

What code did you end up using?  I'm trying to implement it on my site and am running into the same error you posted.  :(
Cody

Re: How to add specified css class for every page in menu?

Post by Cody »

My functional code is:

Code: Select all

<li class="{$node->alias}">
I hope it helps you:-)
Post Reply

Return to “General Discussion”