am-impact / amnav

Navigation plugin for Craft
168 stars 20 forks source link

Need a page.first conditional #21

Closed pixeljitsu closed 9 years ago

pixeljitsu commented 9 years ago

It would be awesome if there were a way to conditionally use page.first with craft.amNav.getNavRaw as with page.active :

{% if page.active %}class="active"{% endif %}

Like this:

{% if page.first %}class="first"{% endif %}

I have a situation where top level dropdowns must have javascript:void(0) hrefs and there does not seem to be a way to assign the top level as being the active branch. If were able to use page.first then I could assign the active styles to that class and bypass not being able to tell if the menu is active based on the URL location.

{% if page.hasActiveChild %}class="active"{% endif %}

Would be even better for complex menus.

hubertprein commented 9 years ago

While using the recursive macro, use Twig's loop.first to indicate if the node is the first in that level. The proper nodes will be active, based on the current URL.

In your scenario with hasActiveChild, am I correct when I say that one would create a navigation that would have a certain level with a different URI than it's children? If so, I can see why this could be useful in some scenarios.

pixeljitsu commented 9 years ago

So if I create a menu item using my own URL, being '#' or 'javascript:void(0)', then how would loop.first know that the menu has active children?

I have a case now, where the client does not want any of the top level menu items with children to do anything other than hover for the dropdowns. I can see no way to make the make the top level menu with a href of '#' or 'javascript:void(0)' active when one of its children are active.

Perhaps you could consider adding a new "placeholder" menu type that would output '#' or 'javascript:void(0)' in the href and would also register as active if any of its children we active, regardless of the URL structure.

hubertprein commented 9 years ago

Added in the latest release. See release notes for more info.