<p>This is working for me.</p>
<p>Module.php</p>
<pre><code>        Event::on(Cp::class, Cp::EVENT_REGISTER_CP_NAV_ITEMS, function (RegisterCpNavItemsEvent $event) {
            $event-&gt;navItems[] = [
                'url' =&gt; 'modules/video',
                'label' =&gt; 'Video-Converter',
                'icon' =&gt; '@modules/icon-mask.svg',

                'subnav' =&gt; [
                    'inhex' =&gt; [
                        'url' =&gt; 'modules/video/index',
                        'label' =&gt; 'Project-Video',
                    ],
                    'old' =&gt; [
                        'url' =&gt; 'modules/video/old',
                        'label' =&gt; 'Old Projects',
                    ],
                ]
            ];
        });
</code></pre>
<p>And in the templates I am using e.g.</p>
<pre><code>{% extends '_layouts/cp' %}

{% set title = 'Old Projects' %}
{% set selectedSubnavItem = 'old' %}
</code></pre>

CC BY-SA 4.0
2021-03-15T19:11:28.650Z
2021-03-16T12:24:05.607Z
2021-03-16T12:24:05.607Z
Volker Andres
<p>I have a problem with setting up a CP navigation for my <strong>module</strong>.</p>
<p>In module's init() I declared the following:</p>
<pre class="lang-php prettyprint-override"><code>Event::on(
    Cp::class,
    Cp::EVENT_REGISTER_CP_NAV_ITEMS,
    function (RegisterCpNavItemsEvent $event) {
        $event-&gt;navItems[] = [
            'url' =&gt; 'asset-checker-module/broken-links',
            'label' =&gt; 'Checker',
            'subnav' =&gt; [
                'broken-links' =&gt; [
                    'url' =&gt; 'asset-checker-module/broken-links',
                    'label' =&gt; 'Fehlerhafte Links'
                ],
                'unused-assets' =&gt; [
                    'url' =&gt; 'asset-checker-module/unused-assets',
                    'label' =&gt; 'Nicht verwendete Dateien'
                ]
            ]
        ];
    }
);
</code></pre>
<p>So I see my main navigation item, when I click on it, the subnavigation gets expanded, the first element is active. But when I click on the second item, parent item gets collapsed.</p>
<p>I tried to fix it by setting <code>selectedSubnavItem</code> in my template, it did not help.</p>
<p>Any ideas?</p>
<hr />
<p>Running Craft 3.2.7.</p>

CC BY-SA 4.0
2021-03-15T19:03:48.660Z
Having the same issue
Volker Andres
<control-panel><modules><plugin-navigation>
Module's control panel sub-navigation is not working properly
# Module's control panel sub-navigation is not working properly

(Asked by: username_0 on 2020-08-20)

I have a problem with setting up a CP navigation for my module.
In module's init() I declared the following:
Event::on(
    Cp::class,
    Cp::EVENT_REGISTER_CP_NAV_ITEMS,
    function (RegisterCpNavItemsEvent $event) {
        $event->navItems[] = [
            'url' => 'asset-checker-module/broken-links',
            'label' => 'Checker',
            'subnav' => [
                'broken-links' => [
                    'url' => 'asset-checker-module/broken-links',
                    'label' => 'Fehlerhafte Links'
                ],
                'unused-assets' => [
                    'url' => 'asset-checker-module/unused-assets',
                    'label' => 'Nicht verwendete Dateien'
                ]
            ]
        ];
    }
);

So I see my main navigation item, when I click on it, the subnavigation gets expanded, the first element is active. But when I click on the second item, parent item gets collapsed.
I tried to fix it by setting selectedSubnavItem in my template, it did not help.
Any ideas?

Running Craft 3.2.7.

**Tags:** control-panel, modules, plugin-navigation

> **Comments:**
> **username_1**: Having the same issue  

---

## 1 answers

### Answer by username_1 on 2021-03-15. Score: 1 | Accepted answer

This is working for me.
Module.php
        Event::on(Cp::class, Cp::EVENT_REGISTER_CP_NAV_ITEMS, function (RegisterCpNavItemsEvent $event) {
            $event->navItems[] = [
                'url' => 'modules/video',
                'label' => 'Video-Converter',
                'icon' => '@modules/icon-mask.svg',

                'subnav' => [
                    'inhex' => [
                        'url' => 'modules/video/index',
                        'label' => 'Project-Video',
                    ],
                    'old' => [
                        'url' => 'modules/video/old',
                        'label' => 'Old Projects',
                    ],
                ]
            ];
        });

And in the templates I am using e.g.
{% extends '_layouts/cp' %}

{% set title = 'Old Projects' %}
{% set selectedSubnavItem = 'old' %}


---

