Answers.Body: <p>Give this a shot...</p>
  
  <pre><code>{% set transform = (asset.thumbnailCrop.value ?: "portrait") ~ "ThumbSmall" %}
  {{ asset.url(transform) }}
  </code></pre>
  
  <p>If <code>asset.thumbnailCrop</code> is a dropdown field (or similar), you'll need to specifically extract the <strong>value</strong> from it. If no value is found, it'll fall back to using the "portrait" string.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-12-17T13:41:58.020Z
Answers.Text: YOU DID IT :-) Thank you. Earlier suggestions were very similar, just missed ".value". Working great now.
Answers.UserDisplayName: kerns
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-12-13T21:09:05.963Z
Answers.LastActivityDate: 2015-12-13T21:09:05.963Z
Answers.UserDisplayName: Lindsey D
Body: <p>Hopefully simple variable / concatenation question: What is the best way to retrieve the url of a specific asset the name of which should be concatenated from an asset field variable and a text string?</p>
  
  <p>I need to end accessing the url of an asset like so – {{asset.<strong>portrait</strong>ThumbSmall.url}}, but I am in a loop where “<strong>portrait</strong>” could also be “<strong>landscape</strong>” ...or “<strong>square</strong>”, and is derived from an asset field variable on an asset called “thumbnailCrop”. With me so far?</p>
  
  <p>So something like...</p>
  
  <pre><code>    {{asset.thumbnailCrop ~ "ThumbSmall" ~ .url}}
  </code></pre>
  
  <p>…only, unlike this, it should actually work.</p>
  
  <p>I did read this -> <a href="https://craftcms.stackexchange.com/questions/200/how-can-i-incorporate-a-variable-into-a-string">How can I incorporate a variable into a string?</a> …but I’m trying to incorporate a string into a variable. Not sure it applies.</p>
  
  <p>Someone in the Slack channel suggested...</p>
  
  <pre><code>    {% set thumbnail = attribute(asset, thumbnailCrop ~ "ThumbSmall") %}
      {{ thumbnail.url }}
  </code></pre>
  
  <p>But it doesn't work, and I was also wondering if it wasn't possible to make something more compact.</p>
  
  <p>Any help would be appreciated!</p>
  
Tags: <templating><attribute><concatenation>
Title: Accessing and Manipulating a Variable
ThreadText: # Accessing and Manipulating a Variable
  
  (Asked by: username_0 on 2015-12-13)
  
  Hopefully simple variable / concatenation question: What is the best way to retrieve the url of a specific asset the name of which should be concatenated from an asset field variable and a text string?
  
  I need to end accessing the url of an asset like so – {{asset.**portrait**ThumbSmall.url}}, but I am in a loop where “**portrait**” could also be “**landscape**” ...or “**square**”, and is derived from an asset field variable on an asset called “thumbnailCrop”. With me so far?
  
  So something like...
  
  ```
      {{asset.thumbnailCrop ~ "ThumbSmall" ~ .url}}
  
  ```
  
  …only, unlike this, it should actually work.
  
  I did read this -> [How can I incorporate a variable into a string?](https://craftcms.stackexchange.com/questions/200/how-can-i-incorporate-a-variable-into-a-string) …but I’m trying to incorporate a string into a variable. Not sure it applies.
  
  Someone in the Slack channel suggested...
  
  ```
      {% set thumbnail = attribute(asset, thumbnailCrop ~ "ThumbSmall") %}
      {{ thumbnail.url }}
  
  ```
  
  But it doesn't work, and I was also wondering if it wasn't possible to make something more compact.
  
  Any help would be appreciated!
  
  **Tags:** templating, attribute, concatenation
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-12-13. Score: 3 | Accepted answer
  
  Give this a shot...
  
  ```
  {% set transform = (asset.thumbnailCrop.value ?: "portrait") ~ "ThumbSmall" %}
  {{ asset.url(transform) }}
  
  ```
  
  If `asset.thumbnailCrop` is a dropdown field (or similar), you'll need to specifically extract the **value** from it. If no value is found, it'll fall back to using the "portrait" string.
  
  > **Comments:**
  > **username_0**: YOU DID IT :-) Thank you. Earlier suggestions were very similar, just missed ".value". Working great now.  
  
  ---
  
  