@@ -842,28 +842,14 @@ The ``with`` data is what's mounted on the component object.
842
842
Embedded components *cannot * currently be used with LiveComponents.
843
843
844
844
Component HTML Syntax
845
- -----------------
845
+ ---------------------
846
846
847
- .. versionadded :: 2.9
847
+ .. versionadded :: 2.8
848
848
849
849
This syntax was been introduced in 2.8 and is still experimental: it may change in the future.
850
850
851
851
Twig Components come with an HTML-like syntax to ease the readability of your template:
852
852
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
-
867
853
.. code-block :: html+twig
868
854
869
855
<twig:Alert></:Alert>
@@ -874,25 +860,9 @@ You can pass props to your component by using HTML attributes. Suppose you have
874
860
875
861
.. code-block :: html+twig
876
862
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
+
896
866
You can add the ':' prefix to your attribute to indicate that the value
897
867
should be compiled by Twig
898
868
@@ -901,32 +871,11 @@ should be compiled by Twig
901
871
<twig:Alert message="hello" :user="user.id"/>
902
872
903
873
// equal to
904
-
905
874
<twig:Alert message="hello" user="{{ user.id }}"/>
906
875
907
876
// and pass object, or table, or anything you imagine
908
877
<twig:Alert : foo="['col' => ['foo', 'oof']]"/>
909
878
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
-
930
879
You can pass content directly inside your component.
931
880
932
881
.. code-block :: html+twig
@@ -949,6 +898,26 @@ Then in your component template, This becomes a block called content:
949
898
{% block footer %}
950
899
...
951
900
{% 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 %}
952
921
</div>
953
922
954
923
0 commit comments