how do I get the parent node of an entity reference node I have two content types - A and B.  For content type A, there are 5 content items - Aa, Ab, Ac, Ad, Ae.  For content type B, I have two items Ba, Bb.  Content type B has a field that is an entity reference of  content type A.  In a single page I have the following setup:

Ba -> Aa, Ab, Ac, Ad, Ae
Bb -> Aa, Ab, Ac, Ad, Ae

I have a twig template for B and a separate one for A.  When rendering Aa - Ae, I need to know if the container node is Ba or Bb because it is rendered differently.  Ba and Bb know about the referenced entities (Aa - Ae), but the referenced entities don't know who their parent is.  

I've tried using the preprocessor but I can't seem to find a way to get the parent (containter) node.

Any suggestions?

TIA.
You should be able to do this:

$loaded_nodes = \Drupal::entityTypeManager()-&gt;getStorage('node')-&gt;loadByProperties([
  'field_node_reference' =&gt; $node-&gt;id(),
]);
$parent_node = array_pop($loaded_nodes);


Replace the field name with your actual field name.