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

1 Answer 1

2

Use Craft Autocomplete, and it will do all of this for you automatically in PhpStorm:

https://github.com/nystudio107/craft-autocomplete

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.