Comments (12)
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.
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.
Its working somehow in eclipse plugin: https://github.com/pulse00/Symfony-2-Eclipse-Plugin
from idea-php-symfony2-plugin.
And all available variables are stored in _context variable. You can dump, for example, to see them:
dump(_context)
from idea-php-symfony2-plugin.
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.
@hhamon suggested on twitter to autocomplete app.request
, app.user
etc https://twitter.com/hhamon/status/357469386325495808
from idea-php-symfony2-plugin.
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.
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.
Good catch!
from idea-php-symfony2-plugin.
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.
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.
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)
- Add support of Twig named argument for translations HOT 1
- Support YAML inline services
- Autocomplete support for Symfony\Component\Translation\t HOT 1
- issue with Symfony pluguin on phpstorm Windows HOT 1
- Update Symfony meta php files HOT 1
- Consolidate possible actions+icons for "Floating Code Toolbar"
- Drop support for AssetMapper
- Fix conflicting Doctrine querybuilder support with PhpStorm implementation
- Bundle templates path detection does not work for templates in /templates directory
- Macro import improve template name completion
- [Twig] Escaping route names with backslashes HOT 1
- Auto-injecting service in constructor is too high priority HOT 1
- Attribute / Annotation Routing should navigate to one target only
- [Twig] Don't suggest first class callable syntax for lazy loaded twig extensions HOT 1
- 2024.1.273 update broken, causing PHP analysis to fully break HOT 2
- Issue with Symfony Plugin Causing Analyzing Tool to Get Stuck in PhpStorm HOT 4
- #[Route] attribute on method cannot be found if preceded by another attribute HOT 2
- Twig component : no CTRL-click navigation to template for components with a name_prefix
- Renaming a Twig template breaks its usages
- ide-twig.json HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from idea-php-symfony2-plugin.