2

I am currently working on a Craft CMS plugin, which adds functionality on top of assets, that should be callable in templates. I have come up with a Twig Extension that allows templates to call it like this:

{{ image | myCustomMethod }}

However, I would like to provide the method directly on the image itself instead (because it is more readable/intuitive and makes sure image is included in the craft element cache):

{{ image.myCustomMethod() }}

Is it possible for a plugin to extend the AssetFileModel class to do that? If so, how?

Your Answer

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

Browse other questions tagged or ask your own question.