@@ -840,6 +840,86 @@ The ``with`` data is what's mounted on the component object.
840
840
.. note ::
841
841
842
842
Embedded components *cannot * currently be used with LiveComponents.
843
+
844
+ Component HTML Syntax
845
+ ---------------------
846
+
847
+ .. versionadded :: 2.8
848
+
849
+ This syntax was been introduced in 2.8 and is still experimental: it may change in the future.
850
+
851
+ Twig Components come with an HTML-like syntax to ease the readability of your template:
852
+
853
+ .. code-block :: html+twig
854
+
855
+ <twig:Alert></:Alert>
856
+ // or use a self-closing tag
857
+ <twig:Alert/>
858
+
859
+ You can pass props to your component by using HTML attributes. Suppose you have the following component:
860
+
861
+ .. code-block :: html+twig
862
+
863
+ // "withActions" property will be set to true
864
+ <twig:Alert withActions message="hello"></:Alert>
865
+
866
+ You can add the ':' prefix to your attribute to indicate that the value
867
+ should be compiled by Twig
868
+
869
+ .. code-block :: html+twig
870
+
871
+ <twig:Alert message="hello" :user="user.id"/>
872
+
873
+ // equal to
874
+ <twig:Alert message="hello" user="{{ user.id }}"/>
875
+
876
+ // and pass object, or table, or anything you imagine
877
+ <twig:Alert : foo="['col' => ['foo', 'oof']]"/>
878
+
879
+ You can pass content directly inside your component.
880
+
881
+ .. code-block :: html+twig
882
+
883
+ <twig:Alert>
884
+ // any content you want
885
+ <div>
886
+ ...
887
+ </div>
888
+ </twig:Alert>
889
+
890
+ Then in your component template, This becomes a block called content:
891
+
892
+ .. code-block :: html+twig
893
+
894
+ <div class="content">
895
+ {% block content %}
896
+ // and the content will appear in here
897
+ {% endblock %}
898
+ {% block footer %}
899
+ ...
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 %}
921
+ </div>
922
+
843
923
844
924
Contributing
845
925
------------
0 commit comments