@@ -842,28 +842,14 @@ The ``with`` data is what's mounted on the component object.
842842 Embedded components *cannot * currently be used with LiveComponents.
843843
844844Component HTML Syntax
845- -----------------
845+ ---------------------
846846
847- .. versionadded :: 2.9
847+ .. versionadded :: 2.8
848848
849849 This syntax was been introduced in 2.8 and is still experimental: it may change in the future.
850850
851851Twig Components come with an HTML-like syntax to ease the readability of your template:
852852
853- .. code-block :: html+twig
854-
855- {# templates/some_page.html.twig #}
856- <twig:Alert warning : user="user.username" message="I am an alert!">
857- <div class="alert-content">
858- // ... your component content
859- </div>
860- <twig:block name="footer">
861- // ... footer content
862- </twig:block>
863- </twig:Alert>
864-
865- You can now use a custom tag prefix starting by <twig: and your component name
866-
867853.. code-block :: html+twig
868854
869855 <twig:Alert></:Alert>
@@ -874,25 +860,9 @@ You can pass props to your component by using HTML attributes. Suppose you have
874860
875861.. code-block :: html+twig
876862
877- // "warning" property will be set to true
878- <twig:Alert warning></:Alert>
879-
880- <twig:Alert message="hello" :user="user"/>
881-
882- //camel camelCase works too for your properties names
883- <twig:Alert withActions message="hello" :user="user" />
884-
885- And then as usual you can access your properties in your component template
886-
887- .. code-block :: html+twig
888-
889- {# templates/components/Alert.html.twig #}
890-
891- <div class={{ warnings ? 'warnings' : 'success' }}>
892- <p>{{ message }}</p>
893- ...
894- </div>
895-
863+ // "withActions" property will be set to true
864+ <twig:Alert withActions message="hello"></:Alert>
865+
896866You can add the ':' prefix to your attribute to indicate that the value
897867should be compiled by Twig
898868
@@ -901,32 +871,11 @@ should be compiled by Twig
901871 <twig:Alert message="hello" :user="user.id"/>
902872
903873 // equal to
904-
905874 <twig:Alert message="hello" user="{{ user.id }}"/>
906875
907876 // and pass object, or table, or anything you imagine
908877 <twig:Alert : foo="['col' => ['foo', 'oof']]"/>
909878
910- This syntax also allows passing content to blocks:
911-
912- .. code-block :: html+twig
913-
914- <twig:Alert message="hello" :user="user.id">
915- <twig:block name="footer">
916- ...
917- </twig:block>
918- </twig:Alert>
919-
920- And in your component template you can access your embedded block
921-
922- .. code-block :: html+twig
923-
924- <div class="content">
925- {% block footer %}
926- ...
927- {% block footer %}
928- </div>
929-
930879You can pass content directly inside your component.
931880
932881.. code-block :: html+twig
@@ -949,6 +898,26 @@ Then in your component template, This becomes a block called content:
949898 {% block footer %}
950899 ...
951900 {% block footer %}
901+ </div>
902+
903+ In addition to the default block, you can also add named blocks:
904+
905+ .. code-block :: html+twig
906+
907+ <twig:Alert message="hello" :user="user.id">
908+ <twig:block name="footer">
909+ ...
910+ </twig:block>
911+ </twig:Alert>
912+
913+ And in your component template you can access your embedded block
914+
915+ .. code-block :: html+twig
916+
917+ <div class="content">
918+ {% block footer %}
919+ ...
920+ {% block footer %}
952921 </div>
953922
954923
0 commit comments