I'd like to be able to use a variable with the getUrl() method so I can change the filter parameter on the entry page (user controlled) instead of in the source code:
style="background-image = url('{{ getUrl(var) }}')"
I've been trying various approaches to accomplish this: nested output tags and concatenating strings eg:
{% set myFormat = entry.format %}
{% set myImageUrlString = "url('{{ myImage.getUrl('" ~ myFormat ~ "') }}')" %}
...which works in part by outputting the correct string but does not get parsed (duh me!).
Can someone set me straight on the right approach to this and/or let me know whether this is even possible? TIA
July 4th, More details...
I am using a Matrix field to create a customizable grid of images. The 'format' block type is a dropdown list that contains labels/values identical to the image transforms I've created in the CP. The source code I'm using to make this work is as follows:
{% for myBlock in product.imageMatrix.all() %}
{% set myImage = myBlock.image.one %}
{% if myBlock.format == "square" %}{% set myTrans = 'square' %}{% endif %}
{% if myBlock.format == "portrait" %}{% set myTrans = 'portrait' %}{% endif %}
{% if myBlock.format == "landscape" %}{% set myTrans = 'landscape' %}{% endif %}
{% set myImageUrl = myImage.getUrl(myTrans) %}
<div class="cell image-pane-bg" style="background-image: url('{{ myImageUrl }}');"></div>
{% endfor %}
This isn't very elegant but it works. Using myBlock.format as the parameter does not.