Passing data from outer preprocess to inner template I have two templates:
- a child that is printing each item in a list;
- and a parent that calls it
there is also an intermediate Field template that is not involved.

The parent has preprocess access to node field data that each child (node teaser) call needs to use. The child is printing items in a multivalue entity reference field.

How can the child get the data from the parent felds so it can print the right html?

Edit: Just in case it's not clear, the situation is:

paragraph_entity        &lt;== preprocess hook can see field_settingsN which change how "B" and "A" render (e.g. add/change attrs, class).
  -&gt; field_settings_1
  -&gt; field_settings_2
  -&gt; field_references   &lt;== have a defined template "B"
    -&gt; 1.. entity refs to nodes
      -&gt; node           &lt;== have a defined (teaser) template "A"
Done this a couple times, but really got the caching better last time so that it works perfectly... I've put in some fairly verbose comments, but if anything is unclear just shout.

/**
 * Implements HOOK_preprocess_paragraph().
 */
function HOOK_preprocess_paragraph(array &amp;$vars) {
  /** @var \Drupal\paragraphs\Entity\Paragraph $paragraph */
  $paragraph = $vars['paragraph'];
  // Change 'content_reference' to be your paragraph bundle's machine name.
  if ($paragraph-&gt;bundle() === 'content_reference') {
    // Instead of 10 set that to be the max number of references in the field.
    foreach (range(0, 10) as $i) {
      // Change all references to 'field_content_reference' to use your field's
      // machine name.
      if (!isset($vars["content"]["field_content_reference"][$i])) {
        break;
      }
      /** @var \Drupal\node\Entity\Node $node */
      $node = $vars["content"]["field_content_reference"][$i]["#node"];

      // Example change to the Node.
      $node-&gt;field_parent_paragraph = $paragraph;
      $changed = TRUE;

      if (isset($changed)) {
        // If we've changed the node, give a new cache id.
        // THIS IS IMPORTANT!
        $vars["content"]["field_content_reference"][$i]['#cache']['tags'][] = "paragraph:{$paragraph-&gt;id()}";
        $vars["content"]["field_content_reference"][$i]['#cache']['keys'][] = "paragraph";
        $vars["content"]["field_content_reference"][$i]['#cache']['keys'][] = $paragraph-&gt;id();
      }
    }
  }
}


Follow that up with something like:

/**
 * Implements HOOK_preprocess_node().
 */
function HOOK_preprocess_node(array &amp;$vars) {
  /** @var \Drupal\node\Entity\Node $node */
  $node = $vars['node'];
  if (isset($node-&gt;field_parent_paragraph)) {
    $paragraph = $node-&gt;field_parent_paragraph;
    $vars['content']['#attributes']['class'][] = $paragraph-&gt;field_settings_1-&gt;value;
  }
}