1

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.

1
1

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' %}

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.