3

I'm new to Craft, and am not sure whether I've got something weird happening or if what I'm experiencing is expected behavior.

I notice that when I add new entries containing image assets that get transformed (using a control panel transform in this case), that the images don't get transformed until the (template) page is loaded a second time. Therefore, each new page contains empty images and alt-text on its first load. Once I refresh the page, the images appear as expected.

Is this expected behavior? Right now this requires me to visit the page of every entry I create, in order to 'seed' it for use.

Not a deal breaker, but I'm just curious whether there's something I'm doing wrong on my end.

0

2 Answers 2

3

In your config file, set generateTransformsBeforePageLoad to true:

general.php:

return array(
    //other configs
    'generateTransformsBeforePageLoad' => true
);

This will trigger craft to generate and save transforms ahead of loading the page, as explained in the documentation here, this is will also work if you're using a plugin to provide the images.

1
  • Just a small comment; in general, we don't want to create image transforms on page load for performance reasons. It's probably better to use something that allows the transforms to be created on Asset save on the backend. Commented Jun 28, 2018 at 4:11
3

I'm having this problem too. This can't be expected behaviour, can it?

EDIT (SOLVED):

I've learned from MildlyGeeky in the Craft Discord server that this issue is caused by Twig being picky about transforms used in inline CSS styles. It can be resolved by making the transform into a variable and applying the "|raw" filter to it, thus:

{{ transformVariableName|raw }}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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