set current menu item active

Notice: This thread is very old.
Garcha
Member | 9
+
0
-

In the @layout.latte I have a menu, and I want to set current presenter (page) as active, but after searching all day long, could not get help.
I'm sure it's possible in very easy way.
Thanks

Azathoth
Member | 495
+
0
-

I am not sure if it is what you need, but if you need to test if current page is some action,
there is small trick,
$presenter->isLinkCurrent(‘:Presenter:action’);
it returns boolean.

Last edited by Azathoth (2015-04-10 21:48)

F.Vesely
Member | 363
+
0
-

In latte

<a {ifCurrent Presenter:action $params}class="active"{/ifCurrent}>...</a>
duke
Member | 650
+
+3
-

Or more elegantly:

<a n:href="Presenter:action" n:class="$presenter->isLinkCurrent() ? active">...</a>

Or if used with non-linking tag:

<li n:class="$presenter->isLinkCurrent("Presenter:action") ? active">...</li>
Garcha
Member | 9
+
0
-

Thanks, and what if I want to add some additional classes?

BigCharlie
Member | 273
+
0
-

divide by commas, see documentation. I'm not sureif you don't need to use quotes to wrap “regular classes”. Try this example: n:class="$iterator->odd ? alt, 'my-class other-class'".

Last edited by BigCharlie (2015-04-30 14:30)

Garcha
Member | 9
+
0
-

Thanks but I need to have one class name always but also active when active, an this case you said you can switch two versions :/

BigCharlie
Member | 273
+
0
-

I do not understand your comment. Have you tried the proposal and its functionality?

tpr
Member | 55
+
0
-

It worked for me, thanks!