1

I have the following menu structure:

menustructure as you can see, the Item "Clients" points to the same Url as its Child "Client Portfolio" does.

Unfortunately this is not working for my submenu that should consist of the active menuitems childs:

{% set activeNodeId = craft.amNav.getActiveNodeIdForLevel('mainmenu','1') %}

{% if activeNodeId %}
   {{ craft.amNav.getNav('mainmenu', {
    class: 'subnav-inner',
    startFromId: activeNodeId
                }) }}
{% endif %}

The variable "activeNodeId" is always the deepest level child (with that url). So in my case, clicking on "Clients" would result in an activeNodeId = 66. Of course fetching the subitems of this makes no sense because "Client Portfolio" has no children.

Any idea how to force the plugin to take always the correct (parents) id? Or any other way to get the submenu items of the active menu?

1

I finally found a solution of my problem that makes the A&M Nav plugin the perfect choice for me.

The general problem is that amnav offers this function to fetch the activenode id:

{% set activeNodeId = craft.amNav.getActiveNodeIdForLevel('mainmenu',1) %}

This doesn't help because:

Unfortunately the level1 (last parameter) is related to the structure in craft, not in the plugin. In my case the child of a menuitem is not necessarly a child in craft (e.g. a single content).

That means, this function doesn't help me to get the children of a parent that has active children.

This code works to get the active menu item of the first level in the A&M Nav structure:

{# for first level #}
{% set activeNodeId = craft.amNav.getActiveNodeIdForLevel('mainmenu',1) %}

{# for second level #}
{% set nav = craft.amNav.getNavRaw("mainmenu") %}

{% for item in nav %}
    {% if item.hasActiveChild or item.active %}
        {% set activeNodeId = item.id %}
        {% set activeNode = item %}
    {% endif %}
{% endfor %}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.