2

I've got a Matrix field with an image. If I use a pre-defined transform that's defined in Assets everything works fine. However, I need to set a transform manually in the template but it keeps returning an error "The transform “wideCrop” cannot be found!". I have used transforms in templates all over the site that work fine so I'm puzzled why this particular one isn't working.

This is from an embedded template inside the entry:

{% for block in entry.contents %}
    {% for image in block.image %}          

        {% switch block.position %}
            {% case 'full' %}
                {% set wideCrop = { width: 940, height: 360, mode: 'fit' } %}
                <img class="full" src="{{ image.getUrl('wideCrop') }}">   
        {% endswitch %}

    {% endfor %}
{% endfor %} 

Thanks in advance!

3

Remove the single quotes around wideCrop.

<img class="full" src="{{ image.getUrl(wideCrop) }}"> 

Details for why the difference in "template defined" transforms here:

  • Thanks so much. I can't believe I missed the quote marks. Too much code, not enough sleep. :) – David Aug 15 '16 at 23:32

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.