Craft CMS Asked by anvar on July 25, 2021
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.
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' %}
Answered by Volker Andres on July 25, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP