Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Twig] global var autocomplete #558

Closed
gharlan opened this issue Aug 3, 2015 · 3 comments
Closed

[Twig] global var autocomplete #558

gharlan opened this issue Aug 3, 2015 · 3 comments
Labels

Comments

@gharlan
Copy link

gharlan commented Aug 3, 2015

Should be implemented by #31 but it does not work for me (and for @marapper, see #31 (comment))

@Haehnchen
Copy link
Owner

Extensions are supported we just need:

twig:
    globals:
      service: @service

@tklaas
Copy link

tklaas commented Sep 20, 2017

autocomplete for variables that are defined under twig: globals: do work, but using a service does not suggest Methods on this service.

twig:
    globals:
        service: '@AppBundle\Service\MyService'

using this in my template it does work.
{# @var service \AppBundle\Service\MyService #}

but If have to add this in every template, when I add it to my base template which is extended, it does not work within the child template.

Is there another way of doing this?
Maybe with toolbox plugin like @Koc mentioned here:
#468 (comment)
https://github.com/Haehnchen/idea-php-toolbox

@tklaas
Copy link

tklaas commented Oct 2, 2017

@Haehnchen
autocomplete for the global var is working now, but there is no autocomplete for methods on the service like
{{service.user.name}}

having this Service class for example

class MyService 
{
    /**
     * @var AuthorizationCheckerInterface
     */
    private $authorizationChecker;
    /**
     * @var TokenStorageInterface
     */
    private $tokenStorage;

    public function __construct(AuthorizationCheckerInterface $authorizationChecker, TokenStorageInterface $tokenStorage)
    {
        $this->authorizationChecker = $authorizationChecker;
        $this->tokenStorage = $tokenStorage;
    }

    /**
     * @return bool
     */
    public function isLoggedIn()
    {
        return $this->authorizationChecker->isGranted('IS_AUTHENTICATED_REMEMBERED');
    }

    /**
     * @return User|UserInterface
     */
    public function getUser()
    {
        return $this->tokenStorage->getToken()->getUser();
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants