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.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

DieterHolvoet created an issue. See original summary.

dieterholvoet’s picture

Status: Active » Needs review

podarok made their first commit to this issue’s fork.

podarok’s picture

Version: 8.x-2.x-dev » 3.0.2
Status: Needs review » Fixed

tnx

dieterholvoet’s picture

I think you forgot to merge the MR and to give me credit.

podarok’s picture

podarok’s picture

now you have it https://www.drupal.org/u/DieterHolvoet/issue-credits/2895023
this is because you haven't assigned it to you when working on it

Status: Fixed » Closed (fixed)

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