Skip to content

Commit 18edb28

Browse files
committed
[Doc][TwigComponent] Simplify examples, use a tip
1 parent 16a5bfe commit 18edb28

File tree

1 file changed

+16
-26
lines changed

1 file changed

+16
-26
lines changed

src/TwigComponent/doc/index.rst

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -122,25 +122,14 @@ and any other components by running:
122122
123123
Take a moment to fist pump - then come back!
124124

125-
You can also use the ``make`` commands to generate the component PHP and twig files :
125+
.. tip
126126
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:
138129
139-
.. code-block:: terminal
140-
141-
$ php bin/console make:twig-component 'Alert\Danger'
130+
.. code-block:: terminal
142131
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
144133
145134
.. _naming:
146135

@@ -317,22 +306,22 @@ prefix the attribute with ``:`` or use the normal ``{{ }}`` syntax:
317306
// pass object, array, or anything you imagine
318307
<twig:Alert :foo="{col: ['foo', 'oof']}" />
319308

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``.
322311

323-
To pass the boolean ``false``, you can pass a Twig expression
312+
To pass the boolean ``false``, you can pass a Twig expression
324313
``{{ false }}`` or use the dynamic syntax (with the ``:`` prefix):
325314

326315
.. code-block:: html+twig
327316

328-
{# ❌ the string 'false' is converted to the boolean 'true' #}
317+
{# ❌ the string 'false' is converted to the boolean 'true' #}
329318
<twig:Alert message="..." withCloseButton="false" />
330319

331320
{# ✅ use the 'false' boolean value #}
332321
<twig:Alert message="..." withCloseButton="{{ false }}" />
333-
322+
334323
{# ✅ use the dynamic syntax #}
335-
<twig:Alert message="..." :withCloseButton="false" />
324+
<twig:Alert message="..." :withCloseButton="false" />
336325

337326
Don't forget that you can mix and match props with attributes that you
338327
want to render on the root element:
@@ -527,14 +516,14 @@ component use a ``PreMount`` hook::
527516
an error will be prompted, indicating that one or more options do not exist.
528517
To avoid this, use the ``ignoreUndefined()`` method with ``true``.
529518
See `ignore not defined options`_ for more info::
530-
519+
531520
$resolver->setIgnoreUndefined(true);
532-
521+
533522
The major drawback of this configuration is that the OptionsResolver will
534523
remove every non-defined option when resolving data. To maintain props that
535524
have not been defined within the OptionsResolver, combine the data from the
536525
hook with the resolved data::
537-
526+
538527
return $resolver->resolve($data) + $data;
539528

540529
The data returned from ``preMount()`` will be used as the props for mounting.
@@ -711,7 +700,7 @@ You can also add more, named blocks:
711700
</div>
712701

713702
Render these in the normal way.
714-
703+
715704
.. code-block:: html+twig
716705

717706
<twig:Alert type="success">
@@ -1791,3 +1780,4 @@ https://symfony.com/doc/current/contributing/code/bc.html
17911780
.. _`shadcn/ui`: https://ui.shadcn.com
17921781
.. _`tales-from-a-dev/twig-tailwind-extra`: https://github.com/tales-from-a-dev/twig-tailwind-extra
17931782
.. _`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

Comments
 (0)