Several fields in a node need to be displayed in a particular way depending upon which newsletter body they are a part of. How do I pass a variable from the enclosing newsletter body to enclosed fields so that I can inform the field of its context and control the way the field is displayed?
I have a theme that has preprocess functions both for the newsletter body and for fields contained within the body.
I want to set a variable in the body preprocess function, and its related twig template, that can be inspected by the field preprocess function, and/or its own template.
In other words, I want each field to be aware of the body context in which it is being rendered.
Specifically, I have
mytheme_preprocess_simplenews_newsletter_body() that sets a variable (
$variables['summons'] = 'placeholder';) which can be inspected (and also set) by the theme's simplenews-newsletter-body.html.twig template, but (because it's in a different render array) is subsequently neither visible to
mytheme_preprocess_field() nor field--node--title.html.twig.
How do I communicate between the two render arrays?
There are apparently global variables like
Sometimes, it is possible to achieve this kind of thing by cascading CSS class attributes from a containing element to a contained element. This is not generally satisfactory and in this particular case, it won't wash on different target mail clients unpredictable treatment of CSS.