1

I have set transforms in admin but when I call those transforms in Twig nothing happens. 'getUrl('thumb')' shows blank in return although when calling like

 <img src="{{ asset.getUrl('thumb') }}"
  width="{{ asset.getWidth('thumb') }}"
  height="{{ asset.getHeight('thumb') }}">

width and height have values but url is blank. Anyone have idea?

1 Answer 1

1

I think you are missing the targeting of the asset itself.

If you are calling an Entry's asset from a field that expects one single image you can write:

{% set img = entry.fieldName.one() %}
<img 
   src="{{ img.getUrl('thumb') }}" 
   width="{{ img.getWidth('thumb') }}" 
   height="{{ img.getHeight('thumb') }}" />

If you are doing this in a for loop, or your field allows more than one image to be selected you can write:

{% for item in entry.fieldName %}
    {% set img = item.one() %}
    <img 
       src="{{ img.getUrl('thumb') }}" 
       width="{{ img.getWidth('thumb') }}" 
       height="{{ img.getHeight('thumb') }}" />
{% endfor %}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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