Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mecmartini/49b57dde0ba87503f03153493597fb22 to your computer and use it in GitHub Desktop.
Save mecmartini/49b57dde0ba87503f03153493597fb22 to your computer and use it in GitHub Desktop.
How to render responsive image style on Twig in Drupal
{% set imagePath = 'public://images/default.jpg' %}
{% set responsiveimagestyle = {
'#theme': 'responsive_image',
'#responsive_image_style_id': 'my_responsive_image_style_id',
'#uri': imagePath,
'#alt': 'my alt text',
'#attributes': { class: 'img-responsive' },
} %}
{{ responsiveimagestyle }}
@aastrong
Copy link

Nice little snippet !
Thanks for sharing, came in handy today.

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