Zend Navigation: current page
Asked Answered
X

2

6

There is a method isActive() in Zend_Navigation. But it returns true for all the elements in the current path (parent li is active and all the children too, even when the current is parent li).

Is there any method like isCurrent(), to determine whether the current menu item is the current page?

I just like to add custom class attribute to just one, current element in the whole nested tree of ul's and li's.

Xerophthalmia answered 3/7, 2010 at 7:42 Comment(1)
Are you sure your code is correct? isActive() should return true only for the current page, not parent or child pages.Clothes
J
0

You will need to use your own navigation view script, but that's fairly simple. Then try:

$this->navigation()->findActive($this->yourNavContainer);

That will return an object, var dump it and you will see the data you need. I think the variable is simply called 'page'. Do this before you build your menu, pre/post dispatch, then in your viewscript, do an if statement to check this var against the current looped item (i guess your loop it in a foreach).

Jacquijacquie answered 3/7, 2010 at 23:29 Comment(0)
C
7

easier with:

$activeElement = $view->navigation()->findOneBy('active', 1);

if you're inside your view script you can use:

$activeElement = $this->navigation()->findOneBy('active', 1);
Codon answered 22/2, 2012 at 17:31 Comment(1)
Works better for me than the accepted answer. Thanks!Raskin
J
0

You will need to use your own navigation view script, but that's fairly simple. Then try:

$this->navigation()->findActive($this->yourNavContainer);

That will return an object, var dump it and you will see the data you need. I think the variable is simply called 'page'. Do this before you build your menu, pre/post dispatch, then in your viewscript, do an if statement to check this var against the current looped item (i guess your loop it in a foreach).

Jacquijacquie answered 3/7, 2010 at 23:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.