diff --git a/reference/twig_reference.rst b/reference/twig_reference.rst index dd6aeac2d0a..970f0bee400 100644 --- a/reference/twig_reference.rst +++ b/reference/twig_reference.rst @@ -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`. | +----------------------------------------------------+--------------------------------------------------------------------------------------------+ -| ``_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 | ++---------------------------------------------------+------------------------------------------------------------------------------+ + Global Variables ----------------