Global app object in twig

I'm trying to have the object "app" autocomplete in twig and be able to have "app.user.username" in the autocomplete, I've tried thousands of ways, and it doesn't seem to work. Please can you help me?

here are the ways that I've used, besides that I have the Symfony plugin and PHPToolbox installed

 

1-Create an global extension in twig:

https://twig.symfony.com/doc/2.x/advanced.html#id1

<?php

namespace App\Twig;

use Symfony\Bridge\Twig\AppVariable;
use Twig\Extension\AbstractExtension;
use Twig\Extension\GlobalsInterface;

class GlobalExtension extends AbstractExtension implements GlobalsInterface
{
public function getGlobals(): array
{
return [
'app' => new AppVariable()
];

}

}

it's not work.

 

2- I've tried to do the same thing I do to make it work in my PHP classes, used phpstorm.meta.php

override(\Symfony\Bundle\FrameworkBundle\Controller\ControllerTrait::getUser(), map([
'' => \App\Entity\User::class,
]));

override(\Symfony\Bridge\Twig\AppVariable::getUser(), map([
'' => \App\Entity\User::class,
]));

but it not work in twig

:(

3- ..?

4- ..?

 

 
1
4 comments

Isn't that possible?

0

Thansk for the incredible support.

0

Sorry for responding slowly. This is a community forum which is not the best way to get support.
Please consider creating a support ticket next time you need help:
https://intellij-support.jetbrains.com/hc/en-us/requests/new?ticket_form_id=66731
(Not that it's an excuse for ignoring your request for three days)

Unfortunately, there's no completion implemented for Twig at all: https://youtrack.jetbrains.com/issue/WI-28093
So far, there's nothing we can offer you as a solution. Again, our apologies.

0

Well better late than never, I see that the issue was opened 4 years ago, so I better hope sitting down or better not wait.

Thanks anyway

0

Please sign in to leave a comment.