From: Fabien Potencier Date: Wed, 1 May 2013 04:57:38 +0000 (+0200) Subject: tweaked docs for the set tag (closes #1029) X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=b7abf4d5e5ab0edea914ea1077e3d48fcc5c8561;p=web%2Fkonrad%2Ftwig.git tweaked docs for the set tag (closes #1029) --- diff --git a/doc/tags/set.rst b/doc/tags/set.rst index 15090e7..4f2b2ab 100644 --- a/doc/tags/set.rst +++ b/doc/tags/set.rst @@ -2,28 +2,48 @@ ======= Inside code blocks you can also assign values to variables. Assignments use -the ``set`` tag and can have multiple targets: +the ``set`` tag and can have multiple targets. + +Here is how you can assign the ``bar`` value to the ``foo`` variable: .. code-block:: jinja - {% set foo = 'foo' %} + {% set foo = 'bar' %} - {% set foo = [1, 2] %} +After the ``set`` call, the ``foo`` variable is available in the template like +any other ones: - {% set foo = {'foo': 'bar'} %} +.. code-block:: jinja + + {# displays bar #} + {{ foo }} +The assigned value can be any valid :ref:`Twig expressions +`: + +.. code-block:: jinja + + {% set foo = [1, 2] %} + {% set foo = {'foo': 'bar'} %} {% set foo = 'foo' ~ 'bar' %} +Several variables can be assigned in one block: + {% set foo, bar = 'foo', 'bar' %} + {# is equivalent to #} + + {% set foo = 'foo' %} + {% set bar = 'bar' %} + The ``set`` tag can also be used to 'capture' chunks of text: .. code-block:: jinja {% set foo %} - + {% endset %} .. caution:: diff --git a/doc/templates.rst b/doc/templates.rst index 94eb9f9..f87b036 100644 --- a/doc/templates.rst +++ b/doc/templates.rst @@ -544,6 +544,8 @@ macro call: {% endmacro %} +.. _twig-expressions: + Expressions -----------