2

Having issues getting Craft to use a transform I set in the CP: squarePhoto. I keep getting a template error, even though that transform exist.

Variable "squarePhoto" does not exist

The template code in question is:

{% for asset in block.photoImages %}
    <img src="{{ asset.getUrl(squarePhoto) }}" alt="{{ asset.title }}">
{% endfor %}

After digging through other threads, I saw that Craft adds a subfolder to the directory with the transform name–this has not been generated. What am I missing?

I've also added the config var 'generateTransformsBeforePageLoad' => true, to my general.php to see if that made a difference.

6

It's a very subtle difference, but what you have added there is a variable, when what you are looking for is a string.

<img src="{{ asset.getUrl('squarePhoto') }}" alt="{{ asset.title }}">

Notice the difference?

Your current way would be correct if you had set a variable somewhere with the name of squarePhoto, like so:

{% set squarePhoto = 'transformName' %}

Check out the Twig Primer in the Craft docs.

1
  • 1
    Very subtle indeed! Thanks for the description to, it helps to understand the differences
    – Siebird
    Sep 24 '14 at 17:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.