Created
November 21, 2017 14:37
-
-
Save krisrobinson/1279375c9742c751ad9b2ef31d5a7e58 to your computer and use it in GitHub Desktop.
Drupal 8 loop through and print paragraph fields in field.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div{{ attributes }}> | |
{# First check if there is a section video #} | |
{% for item in items if item.content['#paragraph'].field_section_video is not null %} | |
{% if loop.first %} | |
<div{{ item.attributes }}>{{ item.content }}</div> | |
{% endif %} | |
{% else %} | |
{# If no video was found, check if there is a section_image #} | |
{% for item in items if item.content['#paragraph'].field_section_image is not null %} | |
{% if loop.first %} | |
<div{{ item.attributes }}>{{ item.content }}</div> | |
{% endif %} | |
{% else %} | |
{# Revert to default#} | |
<div {{ item.attributes }} class="no-media">No Media</div> | |
{% endfor %} | |
{% endfor %} | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment