Drupal - How to print paragraphs in twig template?

Not sure if it's possible with your current approach. Here is how I would approach this.

In your node template file just do a {{ content.field_pr }}

Create a template file for your paragraph.

paragraph__[view_mode] (e.g. paragraph--default.html.twig)

paragraph__[type] (e.g. paragraph--image.html.twig)

paragraph__[type]__[view_mode] (e.g. paragraph--image--default.html.twig)

source: Theming in Paragraphs for Drupal 8

In paragraph--[type].html.twig you do {{ content.field_text }} and {{ content.field_color }}


To print paragraph fields in a loop (for sliders, etc.) in page--content-type.html.twig use below snippet:

{% for item in node.field_paragraph_mac_name %}
  {{ item.entity.field_title.value }}
  <img src="{{ file_url(item.entity.field_image.entity.fileuri) }}" />
{% endfor %}

I figured this one out. With Twig Tweak enabled you can print paragraphs from the node object without using content:

{% for item in node.field_my_paragraph_field %}
     {{ drupal_entity('paragraph', item.target_id) }}
{% endfor %}

Tags:

Nodes

Theming

8