1

I'm trying to calculate some image sizes for Imager.

This works:

{% set imageSizes = [{ height: imageHeight * 4}, { height: imageHeight * 3}, { height: imageHeight * 2}, { height: imageHeight}] %}

But how do i get halfs?

imageHeight * 2.5, imageHeight * 0.5 or imageHeight / 2 does not work.

Edit:
It was my own fault.
I checked the array and only saw width's. I set the images sizes in the CP and to:

{% if imageHeight is not empty %}
  {% set imageSizes = [{ height: imageHeight * 4}... %}
{% else %}
  {% set imageSizes = [{ width: imageWidth * 4}... %}
{% endif %}

I only wrote the half calculation in "if imageHeight" for testing. But the entry i use for testing has only width's...

3

I'm going to guess something else is wrong in your templates, because all the examples you provided definitely work in Twig. Perhaps you have an error or typo on an earlier line that's preventing your imageHeight calculations from working. I'd also check what imageHeight is set to as that isn't apparent from the snippet you provided; you can check by dumping the value - {{ dump(imageHeight) }}.

1
  • Yes it was a stupid mistake i made. See my edit. – MrGlasspoole Aug 27 '19 at 2:08

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.