Add attributes to a template based on current node I need to add a style attribute to the .region-content tag in order to set a field-dependent background image.

How do I do this? I have the node in page.html.twig in the page.node variable, but not in region.html.twig, and there doesn't seem to be a way to transfer it from one to the other at that level.

Edit:

This seemed like a good first attempt:

function [THEME]_preprocess_page(&amp;$variables) {
  $variables['page']['content']['#context']['node'] = $variables['node'];
}


function [THEME]_preprocess_region(&amp;$variables) {
  if ($variables['region'] == 'content') {
    var_dump($variables['context']);
  }
}


Unfortunately, that doesn't work - the context variable is still an empty array. How do I transfer context from one theme element to one of its children?

This could be done with a global* variable or something, but that looks horrendously inelegant.

Edit: Well, preferably a call to a function with a static variable, but that still seems like a bad hack.
In Drupal 8 you can get the node object from the routing system:

function [THEME]_preprocess_region(&amp;$variables) {
  if ($node = \Drupal::routeMatch()-&gt;getParameter('node')) {
    $variables['node'] = $node;
}