Skip to content

Instantly share code, notes, and snippets.

@RainbowArray
Created February 15, 2016 21:08
Show Gist options
  • Save RainbowArray/b4fd03e4473ed8a6c7eb to your computer and use it in GitHub Desktop.
Save RainbowArray/b4fd03e4473ed8a6c7eb to your computer and use it in GitHub Desktop.
Need to include a node field image in the page.html.twig template with Drupal 8? This is the most straightforward way I've found to do so. (This is using the file entity module.)
{% if node.field_hero_image.entity %}
<img src="{{ file_url(node.field_hero_image.entity.uri.value) }}"
alt="{{ node.field_hero_image.alt }}"
{% if node.field_hero_image.title %}
title="{{ node.field_hero_image.title }}"
{% endif %}
/>
{% endif %}
@DarkteK
Copy link

DarkteK commented Jul 25, 2018

Excellent!! Thx u!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment