Idea-php-symfony2-plugin: [Twig] Global PhpTypes for all files

Created on 12 Dec 2017  路  5Comments  路  Source: Haehnchen/idea-php-symfony2-plugin

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?

Most helpful comment

All 5 comments

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

Was this page helpful?
0 / 5 - 0 ratings