Accessing and Manipulating a Variable 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.portraitThumbSmall.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? …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!
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.