Skip to content

Commit 7d10315

Browse files
committed
Documented selectedchoice test
1 parent c8a44ae commit 7d10315

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

reference/forms/twig_reference.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,24 @@ good idea to include this in your form tag:
192192

193193
<form action="{{ path('form_submit') }}" method="post" {{ form_enctype(form) }}>
194194

195+
Form Tests Reference
196+
--------------------
197+
198+
Tests can be executed by using the ``is`` operator in Twig to create a
199+
condition. Read `the Twig documentation`_ for more information.
200+
201+
.. _form-twig-selectedchoice:
202+
203+
selectedchoice(selected_value)
204+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
205+
206+
This test will check if the current choice is equal to the ``selected_value``
207+
or if the current choice is in the array (when ``selected_value`` is an array).
208+
209+
.. code-block:: jinja
210+
211+
<option {% if choice is selectedchoice(value) %} selected="selected"{% endif %} ...>
212+
195213
.. _`twig-reference-form-variables`:
196214

197215
More about Form Variables
@@ -357,3 +375,4 @@ object:
357375
+------------------------+-------------------------------------------------------------------------------------+
358376

359377
.. _`form_div_layout.html.twig`: https://github.com/symfony/symfony/blob/master/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig
378+
.. _`the Twig documentation`: http://twig.sensiolabs.org/doc/templates.html#test-operator

0 commit comments

Comments
 (0)