Skip to content
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

Merged
merged 5 commits into from Nov 26, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 29 additions & 5 deletions reference/twig_reference.rst
Expand Up @@ -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 |
+====================================================+============================================================================================+
Expand Down Expand Up @@ -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 |
Copy link
Member

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.

| | 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`". |
+----------------------------------------------------+--------------------------------------------------------------------------------------------+
Expand All @@ -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`. |
+---------------------------------------------------------------------------------+-------------------------------------------------------------------+
Expand Down Expand Up @@ -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 |
Copy link
Member

Choose a reason for hiding this comment

The 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 _form_is_choice_selected or _form_is_choice_group functions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it is a replacement for _form_is_choice_selected(form, choice)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@weaverryan what's exactly wrong with this? I have deleted the _form_is_choice_selected(...) function and added the selectedchoice test, because Symfony2.1 created a test instead of a function.

Copy link
Member

Choose a reason for hiding this comment

The 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
----------------

Expand Down