Git Product home page Git Product logo

Comments (12)

stof avatar stof commented on August 23, 2024 1

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

from idea-php-symfony2-plugin.

adrienbrault avatar adrienbrault commented on August 23, 2024

How is that supposed to work ?

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

from idea-php-symfony2-plugin.

ideea avatar ideea commented on August 23, 2024

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

from idea-php-symfony2-plugin.

ideea avatar ideea commented on August 23, 2024

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

from idea-php-symfony2-plugin.

Haehnchen avatar Haehnchen commented on August 23, 2024

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

from idea-php-symfony2-plugin.

adrienbrault avatar adrienbrault commented on August 23, 2024

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

from idea-php-symfony2-plugin.

hhamon avatar hhamon commented on August 23, 2024

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.

from idea-php-symfony2-plugin.

Haehnchen avatar Haehnchen commented on August 23, 2024

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

from idea-php-symfony2-plugin.

hhamon avatar hhamon commented on August 23, 2024

Good catch!

from idea-php-symfony2-plugin.

Haehnchen avatar Haehnchen commented on August 23, 2024

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

{# variable_name \Foo\Bar #}

from idea-php-symfony2-plugin.

marapper avatar marapper commented on August 23, 2024

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".

from idea-php-symfony2-plugin.

marapper avatar marapper commented on August 23, 2024

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.*

from idea-php-symfony2-plugin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.