Skip to content

Instantly share code, notes, and snippets.

@markconroy
Last active August 29, 2018 10:56
Show Gist options
  • Save markconroy/34dbf76b94a30a29424dcf5415e55894 to your computer and use it in GitHub Desktop.
Save markconroy/34dbf76b94a30a29424dcf5415e55894 to your computer and use it in GitHub Desktop.
{% set image_file_path = content.field_teaser_image[0]['#media'].field_media_image.entity.uri.value %}
{% set image_file_alt = content.field_teaser_image[0]['#media'].field_media_image.0.alt %}
<div class="teaser__image">
{% if node.field_teaser_image_style.value == 'portrait' %}
<a href="{{ url }}">
<img src="{{ image_file_path | image_style('portrait_teaser') }}" alt="{{ image_file_alt }}">
</a>
{% endif %}
{% if node.field_teaser_image_style.value == 'landscape' %}
<a href="{{ url }}">
<img src="{{ image_file_path | image_style('landscape_teaser') }}" alt="{{ image_file_alt }}">
</a>
{% endif %}
</div>
@waako
Copy link

waako commented Mar 29, 2017

For my own reference, background to this snippet here https://www.annertech.com/blog/allow-editors-choose-image-style-drupal-image-fields

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