Take the 2-minute tour ×
Craft CMS Stack Exchange is a question and answer site for administrators, end users, developers and designers for Craft CMS. It's 100% free, no registration required.

I'm trying to get Craft to render an image transform defined in the control panel. No image is added to the "filelocation/_transformhandle" folder and returns the url "/cpresources/transforms/98" where 98 is the transform index.

I have tried clearing the cache and db table already as well as updating the asset index. I have double checked the sources paths and it is not a file permission issue.

Code example as a matrix block:

{% elseif block.type == "slideShow" %} 
{% if block.galleryImages|length>0 %}

{% for image in block.galleryImages %}
    {{ image.aboutText }}
    <img src="{{ image.getUrl('galleryHorizontal') }}">
{% endfor %}
{% endif %}

I tried using the other methods on this page in the docs with the same result. http://buildwithcraft.com/docs/templating/assetfilemodel

Thanks!

share|improve this question

1 Answer 1

up vote 4 down vote accepted

That’s what getUrl() returns if the transform hasn’t been generated yet. When the browser requests that URL, Craft will generate the transform, and respond with a 302 redirect to the actual image URL.

The next time getUrl() gets called (after the transform has been generated), the image URL will be returned directly.

If you would prefer that getUrl() actually generates the transform itself and immediately returns the image URL (perhaps because the output is getting cached by Varnish or something), you can open up craft/config/general.php and add this to your config array:

'generateTransformsBeforePageLoad' => true,

(See http://buildwithcraft.com/docs/config-settings#generateTransformsBeforePageLoad for details.)

share|improve this answer
    
I'm not caching the output. When the code is loaded by the browser the transformed jpg isn't loaded. The console says: Failed to load resource: the server responded with a status of 404 (Not Found). –  FrankFlitton Jul 8 at 17:10
    
Thanks for the hot tip with the 302 redirect! It was a sources issue. I changed it to File System Path: ./assets/images/Gallery/ and URL: /assets/images/Gallery/ in the CP and it works fine now. –  FrankFlitton Jul 8 at 17:50
    
Glad you got it sorted :) –  Brandon Kelly Jul 8 at 19:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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