@@ -122,25 +122,14 @@ and any other components by running:
122
122
123
123
Take a moment to fist pump - then come back!
124
124
125
- You can also use the `` make `` commands to generate the component PHP and twig files :
125
+ .. tip
126
126
127
- .. code-block :: terminal
128
-
129
- $ php bin/console make:twig-component Alert
130
-
131
- If you want your component to reside in a sub directory like ``src/twig/Components/Alert/ `` and make a specific component for a Danger alert you can run:
132
-
133
- .. code-block :: terminal
134
-
135
- $ php bin/console make:twig-component Alert\\Danger
136
-
137
- Or:
127
+ If you use the `Symfony MakerBundle`_, you can easily create a new component
128
+ with the ``make:twig-component`` command:
138
129
139
- .. code-block :: terminal
140
-
141
- $ php bin/console make:twig-component 'Alert\Danger'
130
+ .. code-block:: terminal
142
131
143
- This wil render the php file at `` src\twig\Components\Alert\Danger.php `` and the twig file at `` templates\components\ Alert\Danger.html.twig ``
132
+ $ php bin/console make: twig-component Alert
144
133
145
134
.. _naming :
146
135
@@ -317,22 +306,22 @@ prefix the attribute with ``:`` or use the normal ``{{ }}`` syntax:
317
306
// pass object, array, or anything you imagine
318
307
<twig:Alert : foo="{col: ['foo', 'oof']}" />
319
308
320
- Boolean props are converted using PHP's type juggling rules. The
321
- string ``"false" `` is converted to the boolean ``true ``.
309
+ Boolean props are converted using PHP's type juggling rules. The
310
+ string ``"false" `` is converted to the boolean ``true ``.
322
311
323
- To pass the boolean ``false ``, you can pass a Twig expression
312
+ To pass the boolean ``false ``, you can pass a Twig expression
324
313
``{{ false }} `` or use the dynamic syntax (with the ``: `` prefix):
325
314
326
315
.. code-block :: html+twig
327
316
328
- {# ❌ the string 'false' is converted to the boolean 'true' #}
317
+ {# ❌ the string 'false' is converted to the boolean 'true' #}
329
318
<twig:Alert message="..." withCloseButton="false" />
330
319
331
320
{# ✅ use the 'false' boolean value #}
332
321
<twig:Alert message="..." withCloseButton="{{ false }}" />
333
-
322
+
334
323
{# ✅ use the dynamic syntax #}
335
- <twig:Alert message="..." :withCloseButton="false" />
324
+ <twig:Alert message="..." :withCloseButton="false" />
336
325
337
326
Don't forget that you can mix and match props with attributes that you
338
327
want to render on the root element:
@@ -527,14 +516,14 @@ component use a ``PreMount`` hook::
527
516
an error will be prompted, indicating that one or more options do not exist.
528
517
To avoid this, use the ``ignoreUndefined() `` method with ``true ``.
529
518
See `ignore not defined options `_ for more info::
530
-
519
+
531
520
$resolver->setIgnoreUndefined(true);
532
-
521
+
533
522
The major drawback of this configuration is that the OptionsResolver will
534
523
remove every non-defined option when resolving data. To maintain props that
535
524
have not been defined within the OptionsResolver, combine the data from the
536
525
hook with the resolved data::
537
-
526
+
538
527
return $resolver->resolve($data) + $data;
539
528
540
529
The data returned from ``preMount() `` will be used as the props for mounting.
@@ -711,7 +700,7 @@ You can also add more, named blocks:
711
700
</div>
712
701
713
702
Render these in the normal way.
714
-
703
+
715
704
.. code-block :: html+twig
716
705
717
706
<twig:Alert type="success">
@@ -1791,3 +1780,4 @@ https://symfony.com/doc/current/contributing/code/bc.html
1791
1780
.. _`shadcn/ui` : https://ui.shadcn.com
1792
1781
.. _`tales-from-a-dev/twig-tailwind-extra` : https://github.com/tales-from-a-dev/twig-tailwind-extra
1793
1782
.. _`ignore not defined options` : https://symfony.com/doc/current/components/options_resolver.html#ignore-not-defined-options
1783
+ .. _`Symfony MakerBundle` : https://symfony.com/bundles/SymfonyMakerBundle/current/index.html
0 commit comments