Skip to content

Commit e700325

Browse files
committed
Merge pull request #1962 from WouterJ/twig_ref_21
Added Twig extensions that are new in 2.1
2 parents 2566445 + ee49483 commit e700325

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

reference/twig_reference.rst

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,21 @@ Symfony2 Twig Extensions
55
========================
66

77
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`_
99
then scroll to the bottom).
1010

1111
Symfony2 adds more custom extension on top of Twig to integrate some components
1212
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.
1414

1515
There may also be tags in bundles you use that aren't listed here.
1616

1717
Functions
1818
---------
1919

20+
.. versionadded:: 2.1
21+
The ``csrf_token``, ``logout_path`` and ``logout_url`` functions were added in Symfony2.1
22+
2023
+----------------------------------------------------+--------------------------------------------------------------------------------------------+
2124
| Function Syntax | Usage |
2225
+====================================================+============================================================================================+
@@ -45,13 +48,16 @@ Functions
4548
| ``form_rest(form, variables = {})`` | This will render all fields that have not yet been rendered, more |
4649
| | information in :ref:`the Twig Form reference<reference-forms-twig-rest>`. |
4750
+----------------------------------------------------+--------------------------------------------------------------------------------------------+
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 |
5153
+----------------------------------------------------+--------------------------------------------------------------------------------------------+
5254
| ``is_granted(role, object = null, field = null)`` | This will return ``true`` if the current user has the required role, more |
5355
| | information in ":ref:`book-security-template`" |
5456
+----------------------------------------------------+--------------------------------------------------------------------------------------------+
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+
+----------------------------------------------------+--------------------------------------------------------------------------------------------+
5561
| ``path(name, parameters = {})`` | Get a relative url for the given route, more information in |
5662
| | ":ref:`book-templating-pages`". |
5763
+----------------------------------------------------+--------------------------------------------------------------------------------------------+
@@ -61,9 +67,15 @@ Functions
6167
Filters
6268
-------
6369

70+
.. versionadded:: 2.1
71+
The ``humanize`` filter was added in Symfony2.1
72+
6473
+---------------------------------------------------------------------------------+-------------------------------------------------------------------+
6574
| Filter Syntax | Usage |
6675
+=================================================================================+===================================================================+
76+
| ``text|humanize`` | Makes a technical name human readable (replaces underscores by |
77+
| | spaces and capitalizes the string) |
78+
+---------------------------------------------------------------------------------+-------------------------------------------------------------------+
6779
| ``text|trans(arguments = {}, domain = 'messages', locale = null)`` | This will translate the text into the current language, more |
6880
| | information in :ref:`book-translation-twig`. |
6981
+---------------------------------------------------------------------------------+-------------------------------------------------------------------+
@@ -115,6 +127,18 @@ Tags
115127
| ``{% endtranschoice %}`` | |
116128
+---------------------------------------------------+-------------------------------------------------------------------+
117129

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+
118142
Global Variables
119143
----------------
120144

0 commit comments

Comments
 (0)