Supply front matter metadata to preprocess functions

Created on 5 November 2019, about 5 years ago
Updated 23 June 2023, over 1 year ago

Problem/Motivation

#3064854: Allow Twig templates to use front matter for metadata support introduces the ability for Twig templates to contain front matter metadata.

It would be very helpful to themes to also supply this information to preprocess functions.

One strong use-case being to preprocess the same type of theme hook/template, but for different supported versions where the markup or render structure may have changed between versions.

For example, in Drupal Bootstrap, there could be two templates that are for the same theme hook, but one specifies:

---
bootstrap:
  version: >=3.0.0 <4.0.0
---

While the other template specifies:

---
bootstrap:
  version: >=4.0.0 <5.0.0
---

Being able to access this data in a preprocess function is vital to determine which version of the theme hook/template should be rendered.

Proposed resolution

TBD

Possible solutions:

  1. During the theme registry phase, load the template and add the front matter metadata to the theme hook info array.
  2. Create a hook for theme engines to supply additional metadata for the template in question prior to invoking preprocess functions.
  3. A more permanent and likely performant solution would be to use 📌 Create TemplateDiscovery for plugin managers to use Needs review along with #2869859: [PP-1] Refactor theme hooks/registry into plugin managers so it's just part of the template definition upon discovery.

Remaining tasks

  • Create tests
  • Create patch

User interface changes

None

API changes

TBD

Data model changes

None

Release notes snippet

TBD

📌 Task
Status

Active

Version

11.0 🔥

Component
Theme 

Last updated about 10 hours ago

Created by

🇺🇸United States markhalliwell

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.

Production build 0.71.5 2024