@@ -5,18 +5,21 @@ Symfony2 Twig Extensions
5
5
========================
6
6
7
7
Twig is the default template engine for Symfony2. By itself, it already contains
8
- a lot of build-in functions, filters and tags (`http://twig.sensiolabs.org/documentation `_
8
+ a lot of build-in functions, filters, tags and tests (`http://twig.sensiolabs.org/documentation `_
9
9
then scroll to the bottom).
10
10
11
11
Symfony2 adds more custom extension on top of Twig to integrate some components
12
12
into the Twig templates. Below is information about all the custom functions,
13
- filters and tags that are added when using the Symfony2 Core Framework.
13
+ filters, tags and tests that are added when using the Symfony2 Core Framework.
14
14
15
15
There may also be tags in bundles you use that aren't listed here.
16
16
17
17
Functions
18
18
---------
19
19
20
+ .. versionadded :: 2.1
21
+ The ``csrf_token ``, ``logout_path `` and ``logout_url `` functions were added in Symfony2.1
22
+
20
23
+----------------------------------------------------+--------------------------------------------------------------------------------------------+
21
24
| Function Syntax | Usage |
22
25
+====================================================+============================================================================================+
@@ -45,13 +48,16 @@ Functions
45
48
| ``form_rest(form, variables = {}) `` | This will render all fields that have not yet been rendered, more |
46
49
| | information in :ref: `the Twig Form reference<reference-forms-twig-rest> `. |
47
50
+----------------------------------------------------+--------------------------------------------------------------------------------------------+
48
- | ``_form_is_choice_group(label) `` | This will return ``true `` if the label is a choice group. |
49
- +----------------------------------------------------+--------------------------------------------------------------------------------------------+
50
- | ``_form_is_choice_selected(form, choice) `` | This will return ``true `` if the given choice is selected. |
51
+ | ``csrf_token(intention) `` | This will render a CSRF token, use this function if you want CSRF protection without |
52
+ | | creating a form |
51
53
+----------------------------------------------------+--------------------------------------------------------------------------------------------+
52
54
| ``is_granted(role, object = null, field = null) `` | This will return ``true `` if the current user has the required role, more |
53
55
| | information in ":ref: `book-security-template `" |
54
56
+----------------------------------------------------+--------------------------------------------------------------------------------------------+
57
+ | ``logout_path(key) `` | This will generate the relative logout URL for the given firewall |
58
+ +----------------------------------------------------+--------------------------------------------------------------------------------------------+
59
+ | ``logout_url(key) `` | Equal to ``logout_path(...) `` but this will generate an absolute url |
60
+ +----------------------------------------------------+--------------------------------------------------------------------------------------------+
55
61
| ``path(name, parameters = {}) `` | Get a relative url for the given route, more information in |
56
62
| | ":ref: `book-templating-pages `". |
57
63
+----------------------------------------------------+--------------------------------------------------------------------------------------------+
@@ -61,9 +67,15 @@ Functions
61
67
Filters
62
68
-------
63
69
70
+ .. versionadded :: 2.1
71
+ The ``humanize `` filter was added in Symfony2.1
72
+
64
73
+---------------------------------------------------------------------------------+-------------------------------------------------------------------+
65
74
| Filter Syntax | Usage |
66
75
+=================================================================================+===================================================================+
76
+ | ``text|humanize `` | Makes a technical name human readable (replaces underscores by |
77
+ | | spaces and capitalizes the string) |
78
+ +---------------------------------------------------------------------------------+-------------------------------------------------------------------+
67
79
| ``text|trans(arguments = {}, domain = 'messages', locale = null) `` | This will translate the text into the current language, more |
68
80
| | information in :ref: `book-translation-twig `. |
69
81
+---------------------------------------------------------------------------------+-------------------------------------------------------------------+
@@ -115,6 +127,18 @@ Tags
115
127
| ``{% endtranschoice %} `` | |
116
128
+---------------------------------------------------+-------------------------------------------------------------------+
117
129
130
+ Tests
131
+ -----
132
+
133
+ .. versionadded :: 2.1
134
+ The ``selectedchoice `` test was added in Symfony2.1
135
+
136
+ +---------------------------------------------------+------------------------------------------------------------------------------+
137
+ | Test Syntax | Usage |
138
+ +===================================================+==============================================================================+
139
+ | ``selectedchoice(choice, selectedValue) `` | This will return ``true `` if the choice is selected for the given form value |
140
+ +---------------------------------------------------+------------------------------------------------------------------------------+
141
+
118
142
Global Variables
119
143
----------------
120
144
0 commit comments