2

I use imager to transform images and I want to pass the image ratio as a variable:

{% set customRatio = 1/1 %}

{% set image = craft.assets().one() %}
{% set transformedImage = craft.imager.transformImage(image,
    { width: 1000, ratio: customRatio })
 %}
 <img src="{{ transformedImage.url }}">

This does not work. There is something wrong with how it is passed along. If I pass it as a string: {% set customRatio = '1/1' %}. It doesn't work either. (No errors in both cases).

But when I write it directely into the imager markup like this:

{% set image = craft.assets().one() %}
{% set transformedImage = craft.imager.transformImage(image,
    { width: 1000, ratio: 1/1 })
 %}
 <img src="{{ transformedImage.url }}">

Then it works. But why?

2

Your variable assignment is wrong. {% set customRatio == 1/1 %} should be {% set customRatio = 1/1 %}.

  • yeah, okay. I'm an idiot 🙈 – KSPR Nov 18 '19 at 10:50

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.