-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added Twig extensions that are new in 2.1 #1962
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,18 +5,21 @@ Symfony2 Twig Extensions | |
======================== | ||
|
||
Twig is the default template engine for Symfony2. By itself, it already contains | ||
a lot of build-in functions, filters and tags (`http://twig.sensiolabs.org/documentation`_ | ||
a lot of build-in functions, filters, tags and tests (`http://twig.sensiolabs.org/documentation`_ | ||
then scroll to the bottom). | ||
|
||
Symfony2 adds more custom extension on top of Twig to integrate some components | ||
into the Twig templates. Below is information about all the custom functions, | ||
filters and tags that are added when using the Symfony2 Core Framework. | ||
filters, tags and tests that are added when using the Symfony2 Core Framework. | ||
|
||
There may also be tags in bundles you use that aren't listed here. | ||
|
||
Functions | ||
--------- | ||
|
||
.. versionadded:: 2.1 | ||
The ``csrf_token``, ``logout_path`` and ``logout_url`` functions were added in Symfony2.1 | ||
|
||
+----------------------------------------------------+--------------------------------------------------------------------------------------------+ | ||
| Function Syntax | Usage | | ||
+====================================================+============================================================================================+ | ||
|
@@ -45,13 +48,16 @@ Functions | |
| ``form_rest(form, variables = {})`` | This will render all fields that have not yet been rendered, more | | ||
| | information in :ref:`the Twig Form reference<reference-forms-twig-rest>`. | | ||
+----------------------------------------------------+--------------------------------------------------------------------------------------------+ | ||
| ``_form_is_choice_group(label)`` | This will return ``true`` if the label is a choice group. | | ||
+----------------------------------------------------+--------------------------------------------------------------------------------------------+ | ||
| ``_form_is_choice_selected(form, choice)`` | This will return ``true`` if the given choice is selected. | | ||
| ``csrf_token(intention)`` | This will render a CSRF token, use this function if you want CSRF protection without | | ||
| | creating a form | | ||
+----------------------------------------------------+--------------------------------------------------------------------------------------------+ | ||
| ``is_granted(role, object = null, field = null)`` | This will return ``true`` if the current user has the required role, more | | ||
| | information in ":ref:`book-security-template`" | | ||
+----------------------------------------------------+--------------------------------------------------------------------------------------------+ | ||
| ``logout_path(key)`` | This will generate the relative logout URL for the given firewall | | ||
+----------------------------------------------------+--------------------------------------------------------------------------------------------+ | ||
| ``logout_url(key)`` | Equal to ``logout_path(...)`` but this will generate an absolute url | | ||
+----------------------------------------------------+--------------------------------------------------------------------------------------------+ | ||
| ``path(name, parameters = {})`` | Get a relative url for the given route, more information in | | ||
| | ":ref:`book-templating-pages`". | | ||
+----------------------------------------------------+--------------------------------------------------------------------------------------------+ | ||
|
@@ -61,9 +67,15 @@ Functions | |
Filters | ||
------- | ||
|
||
.. versionadded:: 2.1 | ||
The ``humanize`` filter was added in Symfony2.1 | ||
|
||
+---------------------------------------------------------------------------------+-------------------------------------------------------------------+ | ||
| Filter Syntax | Usage | | ||
+=================================================================================+===================================================================+ | ||
| ``text|humanize`` | Makes a technical name human readable (replaces underscores by | | ||
| | spaces and capitalizes the string) | | ||
+---------------------------------------------------------------------------------+-------------------------------------------------------------------+ | ||
| ``text|trans(arguments = {}, domain = 'messages', locale = null)`` | This will translate the text into the current language, more | | ||
| | information in :ref:`book-translation-twig`. | | ||
+---------------------------------------------------------------------------------+-------------------------------------------------------------------+ | ||
|
@@ -115,6 +127,18 @@ Tags | |
| ``{% endtranschoice %}`` | | | ||
+---------------------------------------------------+-------------------------------------------------------------------+ | ||
|
||
Tests | ||
----- | ||
|
||
.. versionadded:: 2.1 | ||
The ``selectedchoice`` test was added in Symfony2.1 | ||
|
||
+---------------------------------------------------+------------------------------------------------------------------------------+ | ||
| Test Syntax | Usage | | ||
+===================================================+==============================================================================+ | ||
| ``selectedchoice(choice, selectedValue)`` | This will return ``true`` if the choice is selected for the given form value | | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this is new, BUT, I think that we no longer have the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, it is a replacement for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @weaverryan what's exactly wrong with this? I have deleted the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, yes, it's fine - I didn't see that you had removed the 2 other form functions! Merged now - thanks! |
||
+---------------------------------------------------+------------------------------------------------------------------------------+ | ||
|
||
Global Variables | ||
---------------- | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a period after
This will render a CSRF token
- I think we should have 2 different sentences here.