Add Twig Blocks to core template markup

Created on 7 June 2015, over 9 years ago
Updated 25 October 2024, 21 days ago

Problem/Motivation

Currently theming in Drupal 8 still entails overriding entire templates. So for example a collection of node templates for different content types will result in a number of templates all repeating the entire contents of the node template even though each one may only be overriding a small portion of the template or adding mark-up in one area.

It has always been this way with Drupal by default, most of the solutions in the past to provide more granular targeting and flexibility have either involved modules that comprehensively change how layout is handled with Drupal (with admin configuration and functionality) or complex base themes.

Proposed resolution

Provide Twig Block mark-up in core templates that allows Twig extends to be used when overriding templates in themes, allowing for much more 'surgical' targeting of changes.

Currently a Twig Block is only used on one place (The block.html.twig template ironically) and only around the content output of this template. Adding a much more comprehensive Twig block markup in Core will allow themers to immediately reap the same advantages that are gained by Core templates that extend block.html.twig.

This issue is really for general discussion and to test the waters (I believe that the advantages adding comprehensive Twig Block mark-up make it worthwhile but there maybe some technical objections and/or other problems that would follow.

For a better idea of what I am suggesting see an experimental base theme I have started work on, there is more information in the readme.

Beta phase evaluation

Feature request
Status

Active

Version

11.0 🔥

Component

theme system

Created by

🇬🇧United Kingdom chris_hall_hu_cheng

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.

  • 🇳🇱Netherlands timohuisman Leiden, Netherlands

    I'm interested to work on this issue. I'll try to work on this in the coming weeks.

    I like the examples from the IS and #5. I think it would be helpful if the added twig blogs have predictable names. Should the wrapping block always have the same name, something like {% block base %}, or should it be specific to the entity, like {% block node %}?

Production build 0.71.5 2024