Reputation: 21
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
SLIDE PARAGRAPH
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?
Upvotes: 2
Views: 1427
Reputation: 18453
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.
Upvotes: 0