Provide a twig suggestion based on the View Mode

Created on 7 June 2020, almost 5 years ago
Updated 14 January 2025, 3 months ago

Currently, this module it's missing twig template suggestions based on a browser block view mode.
It seems like only these two are provided by default.
block--entity-browser-block--[name].html.twig
block--entity-browser-block.html.twig

Adding a third one, that takes advantage of the $element['#default_view_modes'][$id] would be great.
The ending product would like like this.
block--entity-browser-block--[name]--[view-mode].html.twig
block--entity-browser-block--[name].html.twig
block--entity-browser-block.html.twig

I thought this core patch might address it but it did not
https://www.drupal.org/project/drupal/issues/3062376 ✨ Template suggestions for custom block view modes Fixed

πŸ› Bug report
Status

Postponed: needs info

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States bernardm28 Tennessee

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    The referenced issue has been merged, can confirm if still an issue.

  • πŸ‡ΊπŸ‡ΈUnited States bernardm28 Tennessee

    I can confirm this is stil an issue.
    Tested on 10.3.11.
    One can select the view mode from the UI as seen on the pic below.

    Selecting a different view mode works as expected there. One can switch view modes and see the changes visually on the page.

    However, the twig template suggestion never adds the active view mode to the suggestions.

    That makes it hard to theme a block in multiple ways based on its view mode. You can see the field change between them but have no access to the twig suggestion for it.

Production build 0.71.5 2024