Is it possible to retrieve a control panel defined imagetransform’s dimensions in a front-end template without having to retrieve an asset? Because when there is no asset provided, I can't seem to find a (dynamic) way to get the width and height of the transform in order to calculate dimensions for a placeholder div


In Craft 3 you can call it like this:

{% set transformDimensions = craft.app.assetTransforms.getTransformByHandle('contentWidth') %}

width: {{ transformDimensions.width }}
height: {{ transformDimensions.height }}


Craft does not provide the assetTransformService in the craft.variable but you can include it by yourself. Create a function in your PluginVariable.php that does

public function getTransformationByHandle($handle){
    return craft()->assetTransforms->getTransformByHandle($handle);

and in your twig template
{% set transformation = craft.pluginHandle.getTransformationByHandle('yourHandle') %}

Edit: if you don't have a custom plugin then visit this page Pluginfactory fill out the inputs and select the lightswitch for "variable" paste my function into the /variables/pluginHandleVariable.php file and create a folder with the same name as your pluginhandle (the one you inserted in the input at the page) in /app/plugins/ then go to the control panel, install the plugin.

  • Sorry for the (very) late reply but this just solved my problem! Thank you very much!
    – mdmngz
    Feb 28 '18 at 16:05

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.