I have two templates (and two corresponding preprocess hooks), one rendering a Paragraph, one rendering items from this paragraph.

How to access a variable available in the parent paragraph template (or preprocess Hook) from the items rendering template (or item preprocess hook) ?


{{ content.MyVARIABLE }}  //it works


<div class="row">
  {% for item in items %}
     <div class="col-sm-{{ 12 // parent.MyVARIABLE  }}">
         {{ item }}
{% endfor %}



  • parent. is a bit confusing here, for a field the parent is the entity the field is placed in, possible a paragraph for nested paragraphs, but can be any entity. Or do you mean the paragraphs stored in the field, more like children then?
    – 4uk4
    Commented Jul 27, 2017 at 10:11
  • "parent" means I want to access the paragraph the field is nested in.
    – deivh
    Commented Jul 27, 2017 at 10:22

1 Answer 1


You can't access easily variables from other templates. But you can use the entity objects to access field values.

For a nested paragraph you find the parent paragraph in element['#object']:


{{ element['#object'].field_my_field.value }}
  • This is a really important information. Where can it be found in the documentation?
    – 0711master
    Commented Feb 14, 2018 at 12:04

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.