Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Get Drupal (media) image in Twig template
{#
Source: https://youtu.be/jNqXZ4Jb2No?t=822
DrupalCon Seattle 2019: Pattern Lab: The Definitive How-to
#}
{% set img = node.field_img.entity.getFileUri() %}
{# result: public://images/ocean.jpg #}
{% set imgUrl = file_url(img) %}
{# result: /sites/default/files/ocean.jpg #}
{# requires Twig Tweak Drupal module #}
{% set smallImgUrl = img | image_style('small') %}
{# result: /sites/default/files/styles/small/ocean.jpg #}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment