1

I work on a portfolio with a large number of images with very high sizes and a lot of images transforms. The server on which this site is hosted reach these limits (images generations process are generally blocked), so I would like to experiment with imgix in order to move the transformations of images in the cloud.

I need to tell imgix how to crop images and I prefer to define my transformation types in the Control Panel rather than in the templates. How can I retrieve the mode of an image transformation from its his name?

Is there something like {{ craft.assets.getMode('myTransformName') }} ? I haven't found a method for this in the documentation.

1 Answer 1

1

Not possible out of the box, unfortunately. Asset transforms can be pulled by using the AssetsTransformService, but Craft doesn't expose that service to Twig (unlike the AssetsService, which is what you're working with when you're using craft.assets).

What you could do is to create a simple, custom plugin exposing the AssetsTransformsService to Twig by adding the following to a Variable class in your plugin:

public function assetTransforms()
{
    return craft()->assetTransforms;
}

Then, you'd be able to do something like this in your templates:

{% set transform = craft.myPluginHandle.assetTransforms.getTransformByHandle('myTransformName') %}
<p>The mode is {{ transform.mode }}</p>

Your Answer

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

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