Skip to content

Commit 337e27b

Browse files
authored
Replace example by an AlertComponent
1 parent 2c41789 commit 337e27b

File tree

1 file changed

+19
-22
lines changed

1 file changed

+19
-22
lines changed

src/TwigComponent/doc/index.rst

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -853,52 +853,49 @@ Twig Component came with a new syntax to ease the readability of your template:
853853
.. code-block:: html+twig
854854

855855
{# templates/some_page.html.twig #}
856-
<twig:table :headers="['key', 'value']" :data="[[1, 2], [3, 4]]">
857-
<twig:block name="th_class">
858-
{{ parent() }}
859-
</twig:block>
860-
<twig:block name="td_class">
861-
{{ parent() }}
862-
</twig:block>
863-
<twig:block name="footer">
864-
<div class="data-table-footer">
865-
My footer
866-
</div>
867-
</twig:block>
868-
</twig:table>
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>
869864

870865
You can now use a custom tag prefix starting by <twig: and your component name
871866

872867
.. code-block:: html+twig
873868

874-
<twig:table></:table>
869+
<twig:Alert></:Alert>
875870
// and also self closing tag
876-
<twig:table/>
871+
<twig:Alert/>
877872

878873
You can pass an attribute to your component like any HTML attribute and also use the ':' prefix to your attribute to indicate that the value should be compiled by Twig
879874

880875
.. code-block:: html+twig
881876

882-
// primary will be set to true
883-
<twig:component primary></:component>
884-
<twig:component text="hello" :user="user.id"/>
877+
// Warning will be set to true
878+
<twig:Alert warning></:Alert>
879+
880+
<twig:Alert message="hello" :user="user.id"/>
885881

886882
// equal to
887-
<twig:component text="hello" user="{{ user.id }}"/>
883+
884+
<twig:Alert message="hello" user="{{ user.id }}"/>
888885

889886
// and pass object, or table, or anything you imagine
890-
<twig:component :table="['col' => ['foo', 'oof']]"/>
887+
<twig:Alert :foo="['col' => ['foo', 'oof']]"/>
891888

892889
You can pass content directly inside your component.
893890

894891
.. code-block:: html+twig
895892

896-
<twig:component>
893+
<twig:Alert>
897894
// any content you want
898895
<div>
899896
...
900897
</div>
901-
</twig:component>
898+
</twig:Alert>
902899

903900
Then in your component template, you can access the content put into your component:
904901

0 commit comments

Comments
 (0)