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
| Comment | File | Size | Author |
|---|---|---|---|
| group-content-menu-theme-suggestion-0.patch | 1.21 KB | progga |
Comments
Comment #2
progga commentedComment #3
sergey_gabrielyanThank you progga
Comment #6
heddnThanks for your contributions.