I would like to see a way to define global PhpTypes for my entire project.
I'm using Craft CMS so there is no real way to access the Twig config without overwriting things and I would like to define
{# @var variable_name \Foo\Bar #}
only once and use this variable in all templates. Currently the first line of all my templates is {# @var craft \Craft\CraftVariable #} it would be better to type that only once somewhere and use it everywhere.
Is there a way to do this?
Adding a pseudo global Twig_Extension implemention will help you: https://twig.symfony.com/doc/2.x/advanced.html#id1. But i will provide a better way since #903 is a related problem
Thanks for the reply but I'm not sure how this should help since this is already the case. I have a global variable called craft and I would like to activate the autocomplete function which currently only works with the line {# @var craft \Craft\CraftVariable #} if there is a way to achieve this globally without the online doc please let me know because I don't know how
If you put this file somewhere in your project you will have it for now :)
```php
class Project_Twig_Extension extends Twig_Extension implements Twig_Extension_GlobalsInterface
{
public function getGlobals()
{
return array(
'craft' => new CraftCraftVariable(),
);
}
}
Thank you so much, this is perfect :D
Guten Rutsch in das neue Jahr :P
Formalized this in the Auto-Complete Craft CMS 3 APIs in Twig with PhpStorm article
Most helpful comment
Formalized this in the Auto-Complete Craft CMS 3 APIs in Twig with PhpStorm article