<p>Dropdown fields don't return the selected option as a string. Instead, they return a <a href="https://docs.craftcms.com/api/v4/craft-fields-data-singleoptionfielddata.html" rel="nofollow noreferrer"><code>SingleOptionFieldData</code> object</a> that you can use to access the value of the selected option as well as its label. The <code>setTransform</code> method doesn't know what to do with that object, so you get an error.</p>
<p>This will give you the value of the selected option as a string:</p>
<pre class="lang-twig prettyprint-override"><code>{% set format = block.imageCrop.value %}
</code></pre>
<p>Keep in mind that this may return null if no option is selected, so you may want to set a default:</p>
<pre class="lang-twig prettyprint-override"><code>{% set format = block.imageCrop.value | default('square') %}
</code></pre>
<p>In general, if you're not sure what's going on in your template, dumping the value of variables with the <a href="https://craftcms.com/docs/4.x/dev/tags.html#dd" rel="nofollow noreferrer"><code>dd</code> tag</a> is a good way to find out:</p>
<pre class="lang-twig prettyprint-override"><code>{% set format = block.imageCrop %}
{% dd format %}
</code></pre>
<p>This will show you that you're dealing with an object instead of a string in this case.</p>

CC BY-SA 4.0
2023-09-16T23:04:58.563Z
That did it. I didn't know about the dd tag. Thanks!
artmem
CC BY-SA 4.0
2023-09-16T17:01:34.080Z
2023-09-16T17:01:34.080Z
MoritzLost
<p>I'm using an entry field to set an image transform handle:</p>
<pre><code>{% set format = block.imageCrop %}
</code></pre>
<p>Then I'm trying to pass that to an include:</p>
<pre><code>{% include 'partials/_img' with { format: format } %}
</code></pre>
<p>This is the _img template:</p>
<pre><code>{% do image.setTransform(format) %}
{{ tag('img', {
  src: image.url,
  width: image.width,
  height: image.height,
  srcset: image.getSrcset(['1.5x', '2x', '3x']),
  alt: image.alt ? image.alt : image.title,
}) }}
</code></pre>
<p>This is causing this error: &quot;Setting unknown property: craft\models\ImageTransform::label&quot;</p>
<p>If I change my include to the name of a transform -- with { format: 'square' } -- it works fine.</p>
<p>I'm not sure what the issue is here -- is there an error in my syntax?
I have other instances of this include where I do manually specify the transform, rather than using a custom field (with { format: 'square' }), so ideally, I'd like to be able to do it both ways.</p>

CC BY-SA 4.0
2023-09-16T04:50:17.727Z
If you're using an entries field, you probably have to do `block.imageCrop.one()`.
TheDancingCode
CC BY-SA 4.0
2023-09-16T13:53:05.020Z
It’s just a drop-down field in an entry. I edited the post to clarify.
artmem
<templating><image-transforms><variable><include>
Passing a variable to an include to set an image transform throws Setting Unknown Property error
# Passing a variable to an include to set an image transform throws Setting Unknown Property error

(Asked by: username_0 on 2023-09-16)

I'm using an entry field to set an image transform handle:
{% set format = block.imageCrop %}

Then I'm trying to pass that to an include:
{% include 'partials/_img' with { format: format } %}

This is the _img template:
{% do image.setTransform(format) %}
{{ tag('img', {
  src: image.url,
  width: image.width,
  height: image.height,
  srcset: image.getSrcset(['1.5x', '2x', '3x']),
  alt: image.alt ? image.alt : image.title,
}) }}

This is causing this error: "Setting unknown property: craft\models\ImageTransform::label"
If I change my include to the name of a transform -- with { format: 'square' } -- it works fine.
I'm not sure what the issue is here -- is there an error in my syntax?
I have other instances of this include where I do manually specify the transform, rather than using a custom field (with { format: 'square' }), so ideally, I'd like to be able to do it both ways.

**Tags:** templating, image-transforms, variable, include

> **Comments:**
> **username_1**: If you're using an entries field, you probably have to do `block.imageCrop.one()`.  
> **username_0**: It’s just a drop-down field in an entry. I edited the post to clarify.  

---

## 1 answers

### Answer by username_2 on 2023-09-16. Score: 1 | Accepted answer

Dropdown fields don't return the selected option as a string. Instead, they return a SingleOptionFieldData object that you can use to access the value of the selected option as well as its label. The setTransform method doesn't know what to do with that object, so you get an error.
This will give you the value of the selected option as a string:
{% set format = block.imageCrop.value %}

Keep in mind that this may return null if no option is selected, so you may want to set a default:
{% set format = block.imageCrop.value | default('square') %}

In general, if you're not sure what's going on in your template, dumping the value of variables with the dd tag is a good way to find out:
{% set format = block.imageCrop %}
{% dd format %}

This will show you that you're dealing with an object instead of a string in this case.

> **Comments:**
> **username_0**: That did it. I didn't know about the dd tag. Thanks!  

---

