Skip to content

Instantly share code, notes, and snippets.

@verticalgrain
Created January 9, 2017 18:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save verticalgrain/7ec1be0ee841ec9523d39cecc015d7e3 to your computer and use it in GitHub Desktop.
Save verticalgrain/7ec1be0ee841ec9523d39cecc015d7e3 to your computer and use it in GitHub Desktop.
Timber + Twig srcset image partial
{# Include in views like so: {% include 'partials/image-srcset.twig' with {image_id: post.get_field('hero_background_image'), class: 'hero__background'} %} #}
{# To print image object: {{post.get_field('hero_background_image')|print_r}} #}
<img class="{{class}}" alt="{{TimberImage(image_id).alt}}"
src="{{ TimberImage(image_id).src('large') }}"
srcset="{{ TimberImage(image_id).src('xlarge') }} {{ image_id['sizes']['xlarge-width'] }}w,
{{ TimberImage(image_id).src('hero') }} {{ image_id['sizes']['hero-width'] }}w,
{{ TimberImage(image_id).src('large') }} {{ image_id['sizes']['large-width'] }}w
" />
@verticalgrain
Copy link
Author

Based on work by Christopher Soder-Duncan

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