Skip to content

Commit 435853b

Browse files
TwigComponent: explain how to define default values
1 parent 38a248f commit 435853b

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/TwigComponent/doc/index.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,29 @@ To tell the system that ``icon`` and ``type`` are props and not attributes, use
718718

719719
.. _embedded-components:
720720

721+
Default values
722+
~~~~~~~~~~~~~~
723+
724+
The ``{% props %}`` tag can also be used to define default values of an anonymous component.
725+
726+
.. code-block:: html+twig
727+
728+
{# templates/components/Image.html.twig #}
729+
{% props size = 24 %}
730+
731+
<img src="/image.jpg" width="{{ size }}" height="{{ size }}" alt="">
732+
733+
Then you can call the component with or without defining this value:
734+
735+
.. code-block:: html+twig
736+
737+
<twig:Image size="48"/>
738+
<twig:Image/>
739+
740+
{# renders as: #}
741+
<img src="/image.jpg" width="48" height="48" alt="">
742+
<img src="/image.jpg" width="24" height="24" alt="">
743+
721744
Passing HTML to Components Via Blocks
722745
-------------------------------------
723746

0 commit comments

Comments
 (0)