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

[Feature request] Twig var autocomplete #31

Closed
ideea opened this issue Apr 17, 2013 · 12 comments
Closed

[Feature request] Twig var autocomplete #31

ideea opened this issue Apr 17, 2013 · 12 comments

Comments

@ideea
Copy link

ideea commented Apr 17, 2013

infered_var_twig

@adrienbrault
Copy link
Contributor

How is that supposed to work ?

A template can be called from many different places and variables could contain objects, arrays ... etc

@ideea
Copy link
Author

ideea commented Apr 17, 2013

Its working somehow in eclipse plugin: https://github.com/pulse00/Symfony-2-Eclipse-Plugin

@ideea
Copy link
Author

ideea commented Apr 20, 2013

And all available variables are stored in _context variable. You can dump, for example, to see them:
dump(_context)

@Haehnchen
Copy link
Owner

the plugin only search for the matching shortcut controllermethod of the twig file and resolve the return statement, so no magical stuff :)
i will first try on the twig global function, to see if yaml is fully implemented in phpstorm

@adrienbrault
Copy link
Contributor

@hhamon suggested on twitter to autocomplete app.request, app.user etc https://twitter.com/hhamon/status/357469386325495808

@hhamon
Copy link

hhamon commented Jul 17, 2013

All default app variables are know:

app.request
app.security
app.session
app.user
app.debug
app.environment

You can also add new globals by tweaking the app/config/config_*.yml files:

# app/config/config.yml
twig:
    globals:
        pi: 3.14

In this case you can do app.pi in your templates.

You can also add globals from Twig extensions classes, but for these ones, I don't think we can easily guess them from the IDE.

@Haehnchen
Copy link
Owner

i was trying it before, but there is no "type" support in twig of phpstorm. just giving app.request is easy but providing method completing after this hard. So this one need some hacks with autocomplete and goto provider, but its possible...

dont forget services:

twig:
    globals:
      service: @service

@stof
Copy link
Contributor

stof commented Sep 2, 2013

Be careful. @hhamon was wrong. Setting a pi global variable will not provide app.pi. It will provide pi.
app is not a container for global variables. It is a single global variable referencing an instance of Symfony\Bundle\FrameworkBundle\Templating\GlobalVariables which has a few getters to give access to several objects

@hhamon
Copy link

hhamon commented Sep 2, 2013

Good catch!

Haehnchen added a commit that referenced this issue Oct 27, 2013
…#}, currently parser support inline blocks and global "app" #31
@Haehnchen
Copy link
Owner

so globals are in and more ...
http://symfony2-plugin.espend.de/languages/twig/index.html#phptypes

{# variable_name \Foo\Bar #}

@marapper
Copy link

marapper commented Jun 6, 2015

Still dont work - 0.11.92 in PHPStorm 141.1408

I'd tried add this in yml files for all environments with/out includes (also we have changed path to cache folder - app/cache/dev/appDevDebugProjectContainer.xml actually in app/var/cache/dev/myruDevDebugProjectContainer.xml)

parameters:
  some: 22.2
twig:
    globals:
        some_variable: "Hello"
        another_variable: %some%
        set_of_vars: [1, 2, 3]
        list:
            some: 2

No suggest for

# twig
{{ so }}

and "Can't find declaration".

@marapper
Copy link

marapper commented Jun 6, 2015

app/var/cache/dev/myruDevDebugProjectContainer.xml contains

14796-      <call method="addGlobal">
14797-        <argument>some_variable</argument>
14798-        <argument>2</argument>
14799-      </call>

symfony 2.0.*

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

No branches or pull requests

6 participants