Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Turbo] Document <twig:Turbo:Stream:*> #2481

Open
wants to merge 2 commits into
base: 2.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
170 changes: 164 additions & 6 deletions src/Turbo/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -394,19 +394,177 @@ Let's discover how to use Turbo Streams to enhance your `Symfony forms`_::

{# bottom of new.html.twig #}
{% block success_stream %}
<turbo-stream action="replace" targets="#my_div_id">
<template>
The element having the id "my_div_id" will be replaced by this block, without a full page reload!
<turbo-stream action="replace" targets="#my_div_id">
<template>
The element having the id "my_div_id" will be replaced by this block, without a full page reload!

<div>The task "{{ task }}" has been created!</div>
</template>
</turbo-stream>
<div>The task "{{ task }}" has been created!</div>
</template>
</turbo-stream>
{% endblock %}

Supported actions are ``append``, ``prepend``, ``replace``, ``update``,
``remove``, ``before``, ``after`` and ``refresh``.
`Read the Turbo Streams documentation for more details`_.

Stream Messages and Actions
^^^^^^^^^^^^^^^^^^^^^^^^^^^

To render a ``<turbo-stream>`` element, we recommend using the ``<twig:Turbo:Stream:*>`` Twig Component to avoid typos.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the only reason we added Turbo:Stream:* components?


Append
""""""

.. code-block:: html+twig

<twig:Turbo:Stream:Append target="#dom_id">
Content to append to container designated with the dom_id.
</twig:Turbo:Stream:Append>

{# renders as: #}
<turbo-stream action="append" targets="#dom_id">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

target or targets?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(same comment applies for other examples)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

target becomes targets

<template>
Content to append to container designated with the dom_id.
</template>
</turbo-stream>

smnandre marked this conversation as resolved.
Show resolved Hide resolved
Prepend
"""""""

.. code-block:: html+twig

<twig:Turbo:Stream:Prepend target="#dom_id">
Content to prepend to container designated with the dom_id.
</twig:Turbo:Stream:Prepend>

{# renders as: #}
<turbo-stream action="prepend" targets="#dom_id">
<template>
Content to prepend to container designated with the dom_id.
</template>
</turbo-stream>

smnandre marked this conversation as resolved.
Show resolved Hide resolved
Replace
"""""""

.. code-block:: html+twig

<twig:Turbo:Stream:Replace target="#dom_id">
Content to replace the element designated with the dom_id.
</twig:Turbo:Stream:Replace>

{# renders as: #}
<turbo-stream action="replace" targets="#dom_id">
<template>
Content to replace the element designated with the dom_id.
</template>
</turbo-stream>

.. code-block:: html+twig

{# with morphing #}
<twig:Turbo:Stream:Replace target="#dom_id" morph>
Content to replace the element.
</twig:Turbo:Stream:Replace>

{# renders as: #}
<turbo-stream action="replace" targets="#dom_id" method="morph">
<template>
Content to replace the element.
</template>
</turbo-stream>

smnandre marked this conversation as resolved.
Show resolved Hide resolved
Update
""""""

.. code-block:: html+twig

<twig:Turbo:Stream:Update target="#dom_id">
Content to update to container designated with the dom_id.
</twig:Turbo:Stream:Update>

{# renders as: #}
<turbo-stream action="update" targets="#dom_id">
<template>
Content to update to container designated with the dom_id.
</template>
</turbo-stream>

.. code-block:: html+twig

{# with morphing #}
<twig:Turbo:Stream:Update target="#dom_id" morph>
Content to replace the element.
</twig:Turbo:Stream:Update>

{# renders as: #}
<turbo-stream action="update" targets="#dom_id" method="morph">
<template>
Content to replace the element.
</template>
</turbo-stream>

smnandre marked this conversation as resolved.
Show resolved Hide resolved
Remove
""""""

.. code-block:: html+twig

<twig:Turbo:Stream:Remove target="#dom_id" />

{# renders as: #}
<turbo-stream action="remove" targets="#dom_id"></turbo-stream>

smnandre marked this conversation as resolved.
Show resolved Hide resolved
Before
""""""

.. code-block:: html+twig

<twig:Turbo:Stream:Before target="#dom_id">
Content to place before the element designated with the dom_id.
</twig:Turbo:Stream:Before>

{# renders as: #}
<turbo-stream action="before" targets="#dom_id">
<template>
Content to place before the element designated with the dom_id.
</template>
</turbo-stream>

smnandre marked this conversation as resolved.
Show resolved Hide resolved
After
"""""

.. code-block:: html+twig

<twig:Turbo:Stream:Refresh target="#dom_id">
Content to place after the element designated with the dom_id.
</twig:Turbo:Stream:After>

{# renders as: #}
<turbo-stream action="after" targets="#dom_id">
<template>
Content to place after the element designated with the dom_id.
</template>
</turbo-stream>

smnandre marked this conversation as resolved.
Show resolved Hide resolved
Refresh
"""""""

.. code-block:: html+twig

{# without [request-id] #}
<twig:Turbo:Stream:Refresh />

{# renders as: #}
<turbo-stream action="refresh"></turbo-stream>

.. code-block:: html+twig

{# debounced with [request-id] #}
<twig:Turbo:Stream:Refresh requestId="abcd-1234" />

{# renders as: #}
<turbo-stream action="refresh" request-id="abcd-1234"></turbo-stream>

smnandre marked this conversation as resolved.
Show resolved Hide resolved
Resetting the Form
~~~~~~~~~~~~~~~~~~

Expand Down
Loading