Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-09-16T23:04:58.563Z
Answers.Text: That did it. I didn't know about the dd tag. Thanks!
Answers.UserDisplayName: artmem
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-09-16T17:01:34.080Z
Answers.LastActivityDate: 2023-09-16T17:01:34.080Z
Answers.UserDisplayName: MoritzLost
Body: <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>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-09-16T04:50:17.727Z
Comments.Text: If you're using an entries field, you probably have to do `block.imageCrop.one()`.
Comments.UserDisplayName: TheDancingCode
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-09-16T13:53:05.020Z
Comments.Text: It’s just a drop-down field in an entry. I edited the post to clarify.
Comments.UserDisplayName: artmem
Tags: <templating><image-transforms><variable><include>
Title: Passing a variable to an include to set an image transform throws Setting Unknown Property error
ThreadText: # 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](https://docs.craftcms.com/api/v4/craft-fields-data-singleoptionfielddata.html) 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:
  
  ```twig
  {% 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:
  
  ```twig
  {% 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](https://craftcms.com/docs/4.x/dev/tags.html#dd) is a good way to find out:
  
  ```twig
  {% 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!  
  
  ---
  
  