Replace template_preprocess() and possibly other things with Twig global variables/functions

Created on 13 January 2016, over 8 years ago
Updated 29 March 2024, 3 months ago

Problem/Motivation

For some time we've been talking about moving away from preprocess - via Twig autoescape and other things. This didn't really happen to the extent people hoped during the 8.x cycle though.

So at this point we have a lot of preprocess implementations, and a lot of templates relying on variables prepared by them.

We can't remove preprocess in 8.x, and we can't make variables that were previously available to templates unavailable.

However, we can potentially rationalize specific preprocess implementations, deprecate the use of particular variables etc.

template_preprocess() gets called for every single template render, to generate exactly the same variables to pass in - this would be a good candidate to remove.

Additionally we may be able to define twig variables as objects for other things, so that they're used on demand in the template, rather than always generating strings in preprocess as we currently do. Something like node $submitted would be a good candidate for that.

Proposed resolution

Replace the variables added by template_preprocess() with Twig global variables: http://symfony.com/doc/current/cookbook/templating/global_variables.html

Remaining tasks

User interface changes

API changes

Data model changes

📌 Task
Status

Active

Version

11.0 🔥

Component
Theme  →

Last updated about 13 hours ago

Created by

🇬🇧United Kingdom catch

Live updates comments and jobs are added and updated live.
  • Performance

    It affects performance. It is often combined with the Needs profiling tag.

  • needs profiling

    It may affect performance, and thus requires in-depth technical reviews and profiling.

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.69.0 2024