Hi all,
Now that Twig supports global variables and functions, I will rework the
TwigBundle (http://www.twig-project.org/doc/advanced.html).
Global Variables
----------------
One thing I will add is global variables for common things like the
request and the user (like symfony1 has).
The question is, how do we provide them?
1. Register the request variable directly:
{{ request.query.foo }}
2. Put the request variable under a "namespace":
{{ sf.request.query.foo }}
3. Prefix the variable:
{{ sf_request.query.foo }}
My preference goes to 1 for common variables, and 2 for less common ones
(3 looks too similar to symfony1 ;)).
Globals Functions
-----------------
To generate a URL, you can use the url tag:
{% url 'homepage' %}
This works great, but as it is a tag, it means that it cannot be part of
an expression:
{{ {% url 'homepage' %} ~ '?foo=bar' }}
I propose to remove the url tag and replace it with a function:
{{ url('homepage') }}
It is semantically more correct (a tag should be a language construct,
not something that outputs text to the template), and allows usage anywhere:
{{ url('homepage') ~ '?foo=bar' }}
Again, how do we name those functions?
* Globally:
{{ url('homepage') }}
* Under a namespace
{{ sf.url('homepage') }}
* With a prefix:
{{ sf_url('homepage') }}
As for global variables, heavily used functions like url should use 1,
and less common used ones can probably use 2.
Fabien
--
Fabien Potencier
Sensio CEO - symfony lead developer
sensiolabs.com | symfony-project.org | fabien.potencier.org
Tél: +33 1 40 99 80 80
--
If you want to report a vulnerability issue on symfony, please send it to
security at symfony-project.com
You received this message because you are subscribed to the Google
Groups "symfony developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en