I've created a section with a thumbnail image and also a dropdown to allow the user to select the transformation to apply to that image.

I've pre-created all the asset transformations ready and this is the code I have :

{% set imageTransform = storyEntry.storyThumbnailTransform %}
{% set thumbnailImage = storyEntry.storyThumbnail.first() %}
<img src="{{thumbnailImage.url(imageTransform) }}" alt="" class="post__preview-img post__preview-img--grid">

However, it doesn't appear to be rendering the image. If I output storyEntry.storyThumbnailTransform to the page, it displays the value of the image transform as expected.

What am I doing wrong? Or is there another way to accomplish this?


The imageTransform value is actually an object, representing the entire dropdown field.

Update the first line to this...

{% set imageTransform = storyEntry.storyThumbnailTransform.value %}

This will ensure that the selected value is passed on, instead of the full object.

(The reason that you see the proper value when you output it directly is because the object's __toString method is automatically being called internally.)


Do you not still have to do:

        {% for asset in thumbnailImage %}
            <img src="{{ asset.getUrl(imageTransform) }}" alt="" class="post__preview-img post__preview-img--grid">
        {% endfor %}
  • No need for a loop, because they've already got it narrowed down to the first thumbnail image. Also .getUrl and .url are interchangeable (url is just an alias). – Lindsey D Apr 18 '16 at 14:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.