2

As this tip (Twitter) suggested we can use type hints for Twig in PHPStorm after installing Symfony Support plugin by utilizing its PHPTypes feature, for example putting:

{# @var craft \craft\web\twig\variables\CraftVariable #}

at the top of a template would auto-complete all properties and methods in craft.abc for us.

Type hints for plugins?

How could we get auto-completion for plugin variables?

Let's have a look at the Imager plugin. It is accessible via craft.imager. If I put

{# @var imager \aelvan\imager\variables\ImagerVariable #}

at the top of the template the IDE actually auto-completes for me when I type imager.abc, however this obviously throws an error because Craft expects craft.imager.abc. But the IDE doesn't autocomplete craft.imager.abc. I also tried

{# @var craft.imager \aelvan\imager\variables\ImagerVariable #}

which is not working.

Ugly workaround

If I put craft.imager into a local variable the auto-completion is working:

{# @var imager \aelvan\imager\variables\ImagerVariable #}
{% set imager = craft.imager %}
{% imager.transformedImage(...) %}

Any hints? hahaha

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.