I'm having the requirement to get the child paragraph field values in the parent paragraph twig considering my HTML structure.

So please give me any suggestion to get the child paragraph values in parent_paragraph.html.twig

Comments

infospica’s picture

You can get the child paragraph values in the parent paragraph like shown below.

{% for key,value in content.field_child_paragraph['#items'] %}
{{content.field_child_paragraph[key]['#paragraph'].field_title.value }}
{% endfor %}

field_child_paragraph - The entity reference field machine name of the child paragraph

field_title - The field machine name in the child paragraph

If you want to get the image url from the child paragraph you can render it like shown below.

{% for key,value in content.field_child_paragraph['#items'] %}
{{file_url(content.field_child_paragraph[key]['#paragraph'].field_image.entity.uri.value)}}
{% endfor %}
ajish s’s picture

It working fine. thanks for your reply

Amal_P’s picture

I want to render the paragraph field values in node.html.twig

robin_rosh’s picture

You can also use the same code which is used to render the child paragraph in parent paragraph to get the values in node.html.twig

Amal_P’s picture

Its Working fine