Problem/Motivation

The default template suggestion for Group menus looks for menu--group-menu.html.twig and menu.html.twig only. This makes it difficult to use separate menu templates for different types of Group menus. This can be resolved if we append the menu bundle name in the template suggestion.

Core's Toolbar module has already taken a similar approach. Relevant files:
- Theme declaration.
- Theme usage.
- Default template.

Steps to reproduce

- Turn on Twig debug mode.
- Inspect the markup for a Group menu.

Proposed resolution

Say we have a Group menu called "Foo" in a certain group. In that case the template suggestions should be in this order:
- menu--group-menu.html--foo.twig
- menu--group-menu.html.twig
- menu.html.twig

Patch attached. Resultant markup:

<!-- THEME DEBUG -->
<!-- THEME HOOK: 'menu__group_menu__foo' -->
<!-- FILE NAME SUGGESTIONS:
   * menu--group-menu--foo.html.twig
   x menu--group-menu.html.twig
   x menu--group-menu.html.twig
   * menu.html.twig
-->
<!-- BEGIN OUTPUT from 'modules/contrib/group_content_menu/templates/menu--group-menu.html.twig' -->
        <ul>
              <li>
                    <a href="https://example.net/bar">Bar</a>
              </li>
        </ul>
 <!-- END OUTPUT from 'modules/contrib/group_content_menu/templates/menu--group-menu.html.twig' -->

Remaining tasks

N/A

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Comments

progga created an issue. See original summary.

progga’s picture

Status: Active » Needs review
sergey_gabrielyan’s picture

Thank you progga

  • heddn committed 3ff7d9c2 on 3.0.x authored by progga
    Issue #3328817 by progga, heddn: Add menu bundle in theme template...

  • heddn committed e4d98bf3 on 8.x-1.x authored by progga
    Issue #3328817 by progga, heddn: Add menu bundle in theme template...
heddn’s picture

Status: Needs review » Fixed

Thanks for your contributions.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.