2

I have double nested paragraphs which I am trying to loop through on my twig file. The paragraph structure is as follows:

SLIDER WRAPPER PARAGRAPH

  • reference slide paragraph (entity reference revisions)

SLIDE PARAGRAPH

  • title (text field)
  • reference component library (entity reference revisions)

In my wrapper twig file, I have been able to loop through the reference slide field on the wrapper paragraph and have rendered out the title of the slide, using the below code:

<div class="row">
  <div class="col-sm-12">
    {% for key, item in content.content.field_slide_reference if key|first != '#'%}
     {{ item['#paragraph'].field_title[0].value|raw }}
     {# WANT TO RENDER REFERENCE COMPONENT LIBRARY HERE, BELOW NOT WORKING #}
     {{ item['#paragraph'].field_reference_component_library[0].value }}
    {% endfor %}
  </div>
</div>

Currently I'm receiving the following error:

USER ERROR: "TARGET_ID" IS AN INVALID RENDER ARRAY KEY IN DRUPAL\CORE\RENDER\ELEMENT::CHILDREN() (LINE 98 OF CORE/LIB/DRUPAL/CORE/RENDER/ELEMENT.PHP

Any idea on how I achieve this?

DarkBee
  • 16,592
  • 6
  • 46
  • 58
jessie_ri
  • 21
  • 2
  • Does [this](https://drupal.stackexchange.com/questions/216009/twig-to-print-paragraph-field-in-controller) help? – DarkBee Nov 17 '22 at 09:57

1 Answers1

0

Your error is due to Drupal engine trying to render an array you supply. Drupal rendering logic expects certain elements to be present in the array and warn you if something else is there. If you want to brute-force your content display like this you most likely need to go deeper, showing just certain elements of array item['#paragraph'].field_reference_component_library[0].value.

Alternatively you may try to use 'Twig Tweaks' field_value and field_label filters to do it for you.

Ilya Kochetov
  • 17,988
  • 6
  • 44
  • 60