How to use an image style in a Drupal 8 twig template?

Tyler Marshall picture Tyler Marshall · Nov 3, 2015 · Viewed 14.3k times · Source

I am trying to print an image using an image style that I've created in my drupal 8 theme.

I can print an image in a template by doing {{ content.banner }} but how do I apply the image style to that image? I tried looking for documentation but there doesn't seem to be any out there.

Answer

pavlovich picture pavlovich · Nov 12, 2015

Currently drupal 8 doesn't have special filter for applying image style. Instead you can set new attribute for your image like this:

{% set image = image|merge({'#image_style': 'thumbnail'}) %}

Then simply output your updated image:

{{ image }}

P.S . You can do {{ dump(image) }} to see what attributes you can update