I have referenced Paragraph B in Paragraph A and in preprocess of Paragraph B I want to access host paragraph A. Is this possible with ease. As in case of paragraph references on node we can do paragraph->getParentEntity() ? I had tried same but it still get the parent node :(

1 Answer 1


If you look at the Paragraph class in the module, you will find a public method called getParentEntity that return the parent entity of a Paragraph instance.

So, if you do:

$parent = $paragraph->getParentEntity();

if (isset($parent)) {
  // Your stuff ...

You would have the parent entity in the $parent variable. You can chain the method if there is multiple nested paragraphs. I also suggest using the isset method on the $parent variable because I've encounter some weird issues where random paragraphs returns null.

  • getParentEntity() returns fully loaded entity. no need to load again Commented Mar 31, 2017 at 16:52
  • Okay. I did a quick look of the code and it looked like it returned an id. Does this solve your question?
    – Kevin
    Commented Mar 31, 2017 at 16:52
  • 2
    Well not really I am doing something custom to reuse paragraph Items for specific needs. For example inside a paragraph, I am referencing existing paragraph item(i.e contents of existing paragraph). End up with two paragraph templates and render them. I need something like variable sharing between those two templates to output something conditional. Commented Mar 31, 2017 at 17:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.