Theme suggestion added using add_suggestion Twig filter is not picked up

Created on 23 March 2023, over 1 year ago
Updated 25 May 2023, over 1 year ago

Problem/Motivation

A custom theme suggestion added using the add_suggestion Twig filter is not being picked up.

Steps to reproduce

We have the following template overrides in our custom theme:

  • menu--extras.html.twig
  • menu--extras--main.html.twig
  • menu--extras--main--sub.html.twig

In another template, we want to render the main menu. Not with the usual markup (menu--extras--main.html.twig), but with custom markup for that specific use case. We're doing that using the new add_suggestion Twig filter:

{{ main_menu|add_suggestion('sub') }}

The problem is that while the menu--extras--main--sub.html.twig template exists, the menu--extras--main.html.twig template is still used. This happens because menu_item_extras_theme_suggestions_menu_alter adds its suggestions after the --sub suggestion added using add_suggestion.

Proposed resolution

Change menu_item_extras_theme_suggestions_menu_alter to menu_item_extras_theme_suggestions_menu. This way, its templates don't take precendence over absolutely everything, as they shouldn't. I don't see a reason why it should be an alter anyway, since it's only adding suggestions to the list and not changing existing suggestions.

Remaining tasks

Do it.

πŸ› Bug report
Status

Fixed

Version

3.0

Component

Code

Created by

πŸ‡§πŸ‡ͺBelgium dieterholvoet Brussels

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024