1

I'm using the Imager plugin and Craft for image compression.

Currently, I have something like this:

{% set imagerConfig = { jpegQuality: 80, pngCompressionLevel: 4 } %} 

In another part of my code, I want to do something like:

 {% set largeLogo = craft.imager.transformImage((logo.getUrl('LargeLogo')), imagerConfig) %}

Where I want to do something like this to imagerConfig above:

{% set width = {width: 1000} %} or {%set widthRatio = {width: 1000, ratio: 4/2} %}
imagerConfig.Add(width) //what's the proper syntax for adding an item or even another object(like widthRatio above) to imagerConfig here? 
1

When you use the Twig curly brace {}, key/value pair syntax like you've got imagerConfig set to, you're using the Twig hash literal.

In Twig, if you want to add to an array or hash after it has already been created, you can use the merge filter.

Something like this should do what you're looking for:

{% set imagerConfig = { jpegQuality: 80, pngCompressionLevel: 4 } %}

{% set width = { width: 1000 } %}

{% set imagerConfig = imagerConfig|merge(width) %}

{% set largeLogo = craft.imager.transformImage((logo.getUrl('LargeLogo')), imagerConfig) %}
|improve this answer|||||

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.