File tree Expand file tree Collapse file tree 3 files changed +13
-39
lines changed
LiveComponent/src/Resources/doc Expand file tree Collapse file tree 3 files changed +13
-39
lines changed Original file line number Diff line number Diff line change @@ -249,30 +249,15 @@ Component Attributes
249
249
250
250
.. versionadded :: 2.1
251
251
252
- The `` HasAttributes `` trait was added in TwigComponents 2.1.
252
+ Component attributes were added in TwigComponents 2.1.
253
253
254
254
`Component attributes `_ allows you to render your components with extra
255
255
props that are are converted to html attributes and made available in
256
256
your component's template as an ``attributes `` variable. When used on
257
- live components, these props are persisted between renders. You can enable
258
- this feature by having your live component use the ``HasAttributesTrait ``:
257
+ live components, these props are persisted between renders.
259
258
260
- .. code-block :: diff
261
-
262
- // ...
263
- use Symfony\UX\LiveComponent\Attribute\LiveProp;
264
- + use Symfony\UX\TwigComponent\HasAttributesTrait;
265
-
266
- #[AsLiveComponent('random_number')]
267
- class RandomNumberComponent
268
- {
269
- + use HasAttributesTrait;
270
-
271
- #[LiveProp]
272
- public int $min = 0;
273
-
274
- Now, when rendering your component, you can pass html attributes
275
- as props and these will be added to ``attributes ``:
259
+ When rendering your component, you can pass html attributes as props and
260
+ these will be added to ``attributes ``:
276
261
277
262
.. code-block :: twig
278
263
Original file line number Diff line number Diff line change 8
8
9
9
- Add ` PostMount ` hook component hook to intercept extra props.
10
10
11
- - Add ` HasAttributesTrait ` for components which makes ` attributes ` variable available
12
- in component templates .
11
+ - Add attributes system that takes extra props passed to ` component() ` and converts them
12
+ into a ` ComponentAttributes ` object available in your template as ` attributes ` .
13
13
14
14
- Add ` PreRenderEvent ` to intercept/manipulate twig template/variables before rendering.
15
15
Original file line number Diff line number Diff line change @@ -413,27 +413,16 @@ Component Attributes
413
413
414
414
.. versionadded :: 2.1
415
415
416
- The `` HasAttributes `` trait was added in TwigComponents 2.1.
416
+ Component attributes were added in TwigComponents 2.1.
417
417
418
418
A common need for components is to configure/render attributes for the
419
- root node. You can enable this feature by having your component use
420
- the ``HasAttributesTrait ``. Attributes are any data passed to ``component() ``
421
- that cannot be mounted on the component itself. This extra data is added
422
- to a ``ComponentAttributes `` object that lives as a public property on your
423
- component (available as ``attributes `` in your component's template).
419
+ root node. Attributes are any data passed to ``component() `` that cannot be
420
+ mounted on the component itself. This extra data is added to a
421
+ ``ComponentAttributes `` that is available as ``attributes `` in your
422
+ component's template.
424
423
425
- To use, add the ``HasAttributesTrait `` to your component:
426
-
427
- use Symfony\U X\T wigComponent\A ttribute\A sTwigComponent;
428
- use Symfony\U X\T wigComponent\H asAttributesTrait;
429
-
430
- #[AsTwigComponent('my_component')]
431
- class MyComponent
432
- {
433
- use HasAttributesTrait;
434
- }
435
-
436
- Then render the attributes on the root element:
424
+ To use, in your component's template, render the ``attributes `` variable in
425
+ the root element:
437
426
438
427
.. code-block :: twig
439
428
You can’t perform that action at this time.
0 commit comments