Skip to content

Commit 536e836

Browse files
committed
minor #77 Add docs for the id variable in Turbo Broadcast templates (dunglas)
This PR was merged into the main branch. Discussion ---------- Add docs for the id variable in Turbo Broadcast templates | Q | A | ------------- | --- | Bug fix? | no | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Tickets | symfony/maker-bundle#860 (comment) | License | MIT <!-- Replace this notice by a short README for your feature/bugfix. This will help people understand your PR and can be used as a start for the documentation. Additionally (see https://symfony.com/releases): - Always add tests and ensure they pass. - Never break backward compatibility (see https://symfony.com/bc). - Features and deprecations must be submitted against branch main. --> Commits ------- a0e0d11 Add docs for the id variable in Turbo Broadcast templates
2 parents 4857e1e + a0e0d11 commit 536e836

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/Turbo/README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,6 @@ using the [Mercure](https://mercure.rocks) protocol or any other.
215215

216216
To illustrate this, let's build a chat system with **0 lines of JavaScript**!
217217

218-
219218
Start by installing [the Mercure support](https://symfony.com/doc/current/mercure.html) on your project:
220219

221220
```sh
@@ -379,21 +378,21 @@ Finally, create the template that will be rendered when an entity is created, mo
379378
{% block create %}
380379
<turbo-stream action="append" target="books">
381380
<template>
382-
<div id="{{ 'book_' ~ entity.id }}">{{ entity.title }} (#{{ entity.id }})</div>
381+
<div id="{{ 'book_' ~ id }}">{{ entity.title }} (#{{ id }})</div>
383382
</template>
384383
</turbo-stream>
385384
{% endblock %}
386385
387386
{% block update %}
388-
<turbo-stream action="update" target="book_{{ entity.id }}">
387+
<turbo-stream action="update" target="book_{{ id }}">
389388
<template>
390-
{{ entity.title }} (#{{ entity.id }}, updated)
389+
{{ entity.title }} (#{{ id }}, updated)
391390
</template>
392391
</turbo-stream>
393392
{% endblock %}
394393
395394
{% block remove %}
396-
<turbo-stream action="remove" target="book_{{ entity.id }}"></turbo-stream>
395+
<turbo-stream action="remove" target="book_{{ id }}"></turbo-stream>
397396
{% endblock %}
398397
```
399398

@@ -410,8 +409,8 @@ For instance, if the same entity is displayed on different pages, you can includ
410409
in the template.
411410
Actions applying to non-existing DOM elements will simply be ignored.
412411

413-
The current entity, the action (`create`, `update` or `remove`) and options set on the `Broadcast` attribute
414-
are passed to the template as variables: `entity`, `action` and `options`.
412+
The current entity, the string representation of its identifier(s), the action (`create`, `update` or `remove`) and options set on the `Broadcast` attribute
413+
are passed to the template as variables: `entity`, `id`, `action` and `options`.
415414

416415
### Broadcast Conventions and Configuration
417416

0 commit comments

Comments
 (0)