Answers.Body: <p>Use <a href="https://github.com/nystudio107/craft-autocomplete" rel="nofollow noreferrer">Craft Autocomplete</a>, and it will do all of this for you automatically in PhpStorm:</p>
  <p><a href="https://github.com/nystudio107/craft-autocomplete" rel="nofollow noreferrer">https://github.com/nystudio107/craft-autocomplete</a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-12-20T16:56:14.933Z
Answers.LastActivityDate: 2022-12-20T16:56:14.933Z
Answers.UserDisplayName: andrew.welch
Body: <p>As this tip (<a href="https://twitter.com/nystudio107/status/937866640275988481" rel="nofollow noreferrer">Twitter</a>) suggested we can use type hints for Twig in PHPStorm after installing Symfony Support plugin by utilizing its <a href="https://symfony2-plugin.espend.de/languages/twig/index.html#phptypes" rel="nofollow noreferrer">PHPTypes feature</a>, for example putting:</p>
  
  <p><code>{# @var craft \craft\web\twig\variables\CraftVariable #}</code></p>
  
  <p>at the top of a template would auto-complete all properties and methods in <code>craft.abc</code> for us.</p>
  
  <h2>Type hints for plugins?</h2>
  
  <p>How could we get auto-completion for plugin variables?</p>
  
  <p>Let's have a look at the Imager plugin. It is accessible via <code>craft.imager</code>. If I put</p>
  
  <p><code>{# @var imager \aelvan\imager\variables\ImagerVariable #}</code></p>
  
  <p>at the top of the template the IDE actually auto-completes for me when I type <code>imager.abc</code>, however this obviously throws an error because Craft expects <code>craft.imager.abc</code>. But the IDE doesn't autocomplete <code>craft.imager.abc</code>.
  I also tried</p>
  
  <p><code>{# @var craft.imager \aelvan\imager\variables\ImagerVariable #}</code></p>
  
  <p>which is <em>not working</em>.</p>
  
  <h2>Ugly workaround</h2>
  
  <p>If I put <code>craft.imager</code> into a local variable the auto-completion is working:</p>
  
  <pre><code>{# @var imager \aelvan\imager\variables\ImagerVariable #}
  {% set imager = craft.imager %}
  {% imager.transformedImage(...) %}
  </code></pre>
  
  <p>Any hints? hahaha</p>
  
Tags: <templating><plugins>
Title: PHP types for Twig in PHPStorm
ThreadText: # PHP types for Twig in PHPStorm
  
  (Asked by: username_0 on 2019-12-18)
  
  As this tip ([Twitter](https://twitter.com/nystudio107/status/937866640275988481)) suggested we can use type hints for Twig in PHPStorm after installing Symfony Support plugin by utilizing its [PHPTypes feature](https://symfony2-plugin.espend.de/languages/twig/index.html#phptypes), 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
  
  **Tags:** templating, plugins
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-12-20. Score: 2 | Accepted answer
  
  Use [Craft Autocomplete](https://github.com/nystudio107/craft-autocomplete), and it will do all of this for you automatically in PhpStorm:
  
  <https://github.com/nystudio107/craft-autocomplete>
  
  
  ---
  
  