Skip to content

Instantly share code, notes, and snippets.

@krisrobinson
Created November 21, 2017 14:35
Show Gist options
  • Save krisrobinson/b10b525ad8de755fa225fcf2807fe16d to your computer and use it in GitHub Desktop.
Save krisrobinson/b10b525ad8de755fa225fcf2807fe16d to your computer and use it in GitHub Desktop.
Drupal 8 node.html.twig snippets
{# Kint
{{ kint(content.field_sections['#items'].getValue()) }}
#}
{# if field is defined
{% if node.field_sections[key].entity.field_section_image.entity.fileuri is defined %}
<img src="{{ node.field_sections[key].entity.field_section_image.entity.fileuri | image_style('large') }}">
{% endif %}
#}
{# Print out an image with twig_tweak module's image_style()
{% for key,value in node.field_sections.value %}
<img src="{{ node.field_sections[key].entity.field_section_image.entity.fileuri | image_style('large') }}">
{% endfor %}
#}
{# Print out a particular paragraph with key and field value
{{ node.field_sections[1].entity.field_section_text.value | raw }}
#}
{# Loop through field_sections
<div>
{% for key,value in node.field_sections.value %}
{{ content.field_sections[key] }}
{% endfor %}
</div>
#}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment