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
Comments
Comment #2
catchComment #3
Wim Leers+1 for the principle, but not yet sure how we'll gain much:
Definitely an interesting idea that's worth exploring :)
Comment #4
star-szrTitle fix and adding a related issues that talked about using Twig global vars.
Comment #5
dawehnerWell for 8.1.x it could be tricky, given that other preprocess functions might rely on the existence of those variables, like 'attributes'.
Comment #6
catchAttributes will be hard to change, but I think something like $is_front is unlikely to be changed in preprocess, and something like node $submitted we might be able to consider the specific variables passed to a preprocess function @internal.
Another way to do it would be to have Stable provide the preprocessed variables since that's the bc layer for themes.
So there might be a way to get around it.
Comment #7
joelpittetRegarding attributes yes it's tricky, but not impossible. I've got the content_attributes and title_attributes mostly sorted here #2108771: Remove special cased title_attributes and content_attributes for Attribute creation
Comment #20
catchComment #21
catchComment #24
andypostComment #26
andypostComment #27
catch