<p>I finally found a solution of my problem that makes the A&amp;M Nav plugin the perfect choice for me.</p>

<p>The general problem is that amnav offers this function to fetch the activenode id:</p>

<pre><code>{% set activeNodeId = craft.amNav.getActiveNodeIdForLevel('mainmenu',1) %}
</code></pre>

<p>This doesn't help because:</p>

<p>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). </p>

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

<p>This code works to get the active menu item of the first level in the A&amp;M Nav structure:</p>

<pre><code>{# 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 %}
</code></pre>

CC BY-SA 3.0
2017-08-02T10:29:58.320Z
2017-09-01T18:24:34.210Z
2017-09-01T18:24:34.210Z
Jan
<p>I have the following menu structure:</p>

<p><a href="https://i.sstatic.net/UQjwI.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/UQjwI.png" alt="menustructure"></a>
as you can see, the Item "Clients" points to the same Url as its Child "Client Portfolio" does. </p>

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

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

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

<p>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. </p>

<p>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?</p>

<navigation>
a&m nav - activeNodeId
# a&m nav - activeNodeId

(Asked by: username_0 on 2017-07-30)

I have the following menu structure:

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?

**Tags:** navigation


---

## 1 answers

### Answer by username_0 on 2017-08-02. Score: 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 %}


---

