Claude Skill

turbo

Symfony UX Turbo: Turbo Frames for partial navigation and form submissions, Turbo Streams for multiple updates and Mercure broadcasts, and Turbo Drive for links and forms. Use for turbo-frame, turbo-stream, twig:Turbo, TurboFrame, TurboStreamResponse, turbo_stream_from and #[Broa

LLM Mart · 0 points · 0 views 0 listing impressions 0 install-command copies
Download smnandre-symfony-ux-skills-skills_turbo-78c25ed.zip · 19 KB

Install

skills CLI npx skills add https://github.com/smnandre/symfony-ux-skills/tree/main/skills/turbo
Claude Code claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install smnandre-symfony-ux-skills@llmmart
Git git clone https://github.com/smnandre/symfony-ux-skills.git

The skills CLI installs just this skill, for any of its supported agents. Claude Code installs the whole smnandre/symfony-ux-skills collection as a plugin from our marketplace. Git is the plain clone.

Skill manifest

Turbo

Hotwire Turbo provides SPA-like speed with server-rendered HTML, and leaves the JavaScript to the library. Three components work together:

  • Drive: Automatic AJAX navigation for all links and forms (zero config)
  • Frames: Scoped navigation that updates only one section of the page
  • Streams: Server-pushed DOM mutations (append, replace, remove, etc.)

Decision Tree

Need to update the page?
+-- Full page navigation          -> Turbo Drive (automatic, already active)
+-- Single section from user click -> Turbo Frame
+-- Multiple sections from action  -> Turbo Stream (HTTP response)
+-- Real-time from server/others   -> Turbo Stream (Mercure / SSE)

Installation

composer require symfony/ux-turbo

That's it. Turbo Drive is active immediately: all links and forms become AJAX.

Turbo Drive

Automatic SPA-like navigation. Every <a> click and <form> submit is intercepted, fetched via AJAX, and the <body> is swapped. The browser URL and history update normally.

Disabling for Specific Elements

<!-- Disable on link/form -->
<a href="/external" data-turbo="false">External Link</a>

<!-- Disable for entire section -->
<div data-turbo="false">
    <a href="/normal">Normal link (no Turbo)</a>
</div>

History and Caching

<!-- Replace history instead of push -->
<a href="/page" data-turbo-action="replace">Replace History</a>

<!-- Force full reload when asset changes -->
<link rel="stylesheet" href="/app.css" data-turbo-track="reload">
<script src="/app.js" data-turbo-track="reload"></script>

Turbo Frames

Scope navigation to a section of the page. Links and forms inside a frame update only that frame's content. The rest of the page stays untouched.

Basic Frame

<!-- Page with frame -->
<turbo-frame id="messages">
    <h2>Messages</h2>
    <a href="/messages/1">View Message 1</a>  <!-- Updates only this frame -->
</turbo-frame>

<!-- /messages/1 response must contain a matching frame ID -->
<turbo-frame id="messages">
    <h2>Message 1</h2>
    <p>Content here...</p>
    <a href="/messages">Back to list</a>
</turbo-frame>

The server response is a full HTML page, but Turbo extracts only the matching <turbo-frame> and swaps it in.

Lazy Loading

Load frame content asynchronously after the page renders:

<turbo-frame id="notifications" src="/notifications" loading="lazy">
    <p>Loading...</p>
</turbo-frame>

Target Another Frame

A link inside one frame can update a different frame:

<turbo-frame id="sidebar">
    <a href="/item/1" data-turbo-frame="main-content">View Item</a>
</turbo-frame>

<turbo-frame id="main-content">
    <!-- Content replaced here -->
</turbo-frame>

Break Out of Frame

Navigate the entire page from within a frame:

<turbo-frame id="modal">
    <a href="/dashboard" data-turbo-frame="_top">Go to Dashboard</a>
</turbo-frame>

Frame with Form

Forms inside frames submit and update within that frame. For invalid POSTs, see the form validation response examples.

<turbo-frame id="search-results">
    <form action="/search" method="get">
        <input type="search" name="q">
        <button>Search</button>
    </form>
    <ul>
        {% for item in results %}
            <li>{{ item.name }}</li>
        {% endfor %}
    </ul>
</turbo-frame>

URL Sync

Update the browser URL when a frame navigates (useful for bookmarkable state):

<turbo-frame id="products" data-turbo-action="advance">
    <!-- Browser URL updates when this frame navigates -->
</turbo-frame>

Turbo Streams

Update multiple DOM elements from a single server response. Eight actions available (append, prepend, replace, update, remove, before, after, refresh), each targeting elements by ID or CSS selector.

Stream Actions

<turbo-stream action="append" target="messages">
    <template><div id="msg_1">New message</div></template>
</turbo-stream>

<turbo-stream action="prepend" target="messages">
    <template><div id="msg_0">First!</div></template>
</turbo-stream>

<turbo-stream action="replace" target="notification">
    <template><div id="notification">Updated!</div></template>
</turbo-stream>

<turbo-stream action="update" target="counter">
    <template>42</template>
</turbo-stream>

<turbo-stream action="remove" target="msg_5"></turbo-stream>

<turbo-stream action="before" target="msg_3">
    <template><div id="msg_2">Inserted before</div></template>
</turbo-stream>

<turbo-stream action="after" target="msg_3">
    <template><div id="msg_4">Inserted after</div></template>
</turbo-stream>

<turbo-stream action="refresh"></turbo-stream>

replace and update support an optional method="morph" attribute for smooth DOM morphing instead of full replacement:

<turbo-stream action="replace" method="morph" target="user-card">
    <template><div id="user-card">Updated content</div></template>
</turbo-stream>

Target Multiple Elements (CSS Selector)

Use targets (plural) with a CSS selector to affect multiple elements:

<turbo-stream action="remove" targets=".notification.read"></turbo-stream>

<turbo-stream action="update" targets=".price">
    <template>99.00 EUR</template>
</turbo-stream>

Twig Component Syntax for Streams

Use the <twig:Turbo:Stream:*> components instead of raw HTML:

<twig:Turbo:Stream:Append target="#comments">
    {{ include('comment/_comment.html.twig') }}
</twig:Turbo:Stream:Append>

<twig:Turbo:Stream:Update target="#comment-count">
    {{ count }}
</twig:Turbo:Stream:Update>

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

The component's target prop is rendered as targets, a CSS selector: prefix ids with #.

Symfony Integration

Stream Response from Controller

use Symfony\UX\Turbo\TurboBundle;

#[Route('/messages', name: 'message_create', methods: ['POST'])]
public function create(Request $request): Response
{
    $message = new Message();
    // ... handle form

    $this->em->persist($message);
    $this->em->flush();

    // Only Turbo asks for the stream format: other clients get a redirect
    if (TurboBundle::STREAM_FORMAT === $request->getPreferredFormat()) {
        $request->setRequestFormat(TurboBundle::STREAM_FORMAT);

        return $this->render('message/create.stream.html.twig', [
            'message' => $message,
            'count' => $this->messages->count([]),
        ]);
    }

    return $this->redirectToRoute('message_index', status: Response::HTTP_SEE_OTHER);
}

You can also use the TurboStreamResponse helper or TurboStream helper methods for programmatic stream building.

Stream Template

{# templates/message/create.stream.html.twig #}
<turbo-stream action="append" target="messages">
    <template>
        {{ include('message/_message.html.twig', {message: message}) }}
    </template>
</turbo-stream>
<turbo-stream action="update" target="message-count">
    <template>{{ count }}</template>
</turbo-stream>
<turbo-stream action="replace" target="new-message-form">
    <template>
        {{ include('message/_form.html.twig', {message: null}) }}
    </template>
</turbo-stream>

Detect Frame Request

Since Symfony UX 3.1+, inject the TurboFrame service instead of reading the Turbo-Frame header by hand:

use Symfony\UX\Turbo\TurboFrame;

#[Route('/task/{id}', name: 'app_task_show', methods: ['GET'])]
public function show(TurboFrame $turboFrame, Task $task): Response
{
    if ($turboFrame->isFrameRequest()) {
        $frameId = $turboFrame->getRequestId(); // e.g. "task_details"
        // Render a partial response (or a full page -- Turbo extracts the frame)
    }

    return $this->render('task/show.html.twig', ['task' => $task]);
}

The same check is available in Twig:

{% if turbo_is_frame_request() %}
    <p>Frame ID: {{ turbo_frame_request_id() }}</p>
{% endif %}

To skip the full page layout in frame responses, extend @Turbo/layouts/frame.html.twig: see references/api.md.

Mercure Broadcasts (Real-time)

Requires symfony/mercure-bundle and a Mercure hub. Push changes to all connected browsers via SSE. Since Symfony UX 3.1+, subscribe a page with <twig:Turbo:Stream:From> (requires symfony/ux-twig-component) or the turbo_stream_from() function, which renders a <turbo-mercure-stream-source> element:

{# Subscribe to a string topic #}
<twig:Turbo:Stream:From topics="chat" />

{# Private topic (sends credentials with the EventSource) #}
<twig:Turbo:Stream:From topics="chat" private />

{# Same thing with the function #}
{{ turbo_stream_from('chat', private: true) }}

Publish to that topic from a controller with HubInterface::publish(new Update('chat', $html)), where $html is a rendered stream template.

To broadcast Doctrine entity changes, add #[Broadcast] and subscribe to the entity or its class:

// src/Entity/Message.php
namespace App\Entity;

use Symfony\UX\Turbo\Attribute\Broadcast;

#[ORM\Entity]
#[Broadcast]
class Message
{
    // Creations, updates and deletions are broadcast automatically
}

Subscribe to one entity or to the whole class:

{# Updates of one entity #}
{{ turbo_stream_from(message) }}

{# Every entity of the class (escape the backslashes) #}
<twig:Turbo:Stream:From topics="App\\Entity\\Message" />

<div id="messages">
    {# Messages appear here in real-time #}
</div>
  • #[Broadcast] publishes to a topic derived from the entity class and id: subscribe with the class name (double the backslashes), or with an entity for that entity's updates only ({{ turbo_stream_from(message) }}).
  • Each change renders templates/broadcast/Message.stream.html.twig: it must define the create, update and remove blocks, and receives entity, id, action and the #[Broadcast] options.
  • For updates you publish yourself with HubInterface::publish(), subscribe to the same topic: <twig:Turbo:Stream:From topics="chat" />.

Common Patterns

Inline Edit

<!-- Display mode -->
<turbo-frame id="task_{{ task.id }}">
    <span>{{ task.title }}</span>
    <a href="/tasks/{{ task.id }}/edit">Edit</a>
</turbo-frame>

<!-- Edit mode (response from /tasks/1/edit) -->
<turbo-frame id="task_1">
    <form action="/tasks/1" method="post">
        <input name="title" value="Task title">
        <button>Save</button>
        <a href="/tasks/1">Cancel</a>
    </form>
</turbo-frame>

Modal in Frame

<turbo-frame id="modal"><!-- Empty by default --></turbo-frame>

<a href="/items/1/delete" data-turbo-frame="modal">Delete</a>

<!-- /items/1/delete response -->
<turbo-frame id="modal">
    <dialog open>
        <p>Confirm delete?</p>
        <form method="post">
            <button>Delete</button>
        </form>
        <a href="/items" data-turbo-frame="modal">Cancel</a>
    </dialog>
</turbo-frame>

Flash Messages with Stream

<turbo-stream action="prepend" target="flash-messages">
    <template>
        <div class="alert alert-success" role="alert">
            Item saved successfully!
        </div>
    </template>
</turbo-stream>

Key Principles

Server returns full HTML pages. Turbo works best when the server always returns a complete, valid HTML page. Turbo Drive replaces the body, Turbo Frames extract the matching frame. Don't try to return partial HTML snippets (except for Stream templates).

Frame IDs must match. The frame in the response must have the same id as the frame on the page. If they don't match, Turbo shows an error.

Streams are for side effects. Use Streams when a single action needs to update multiple unrelated parts of the page. If you're only updating one section, a Frame is simpler.

Stimulus complements Turbo. Turbo handles navigation and server communication. Stimulus handles client-side behavior (animations, toggles, clipboard). They work together: Stimulus controllers survive Turbo Frame swaps within their scope, and reconnect properly on Drive navigation.

References

Demos

See Also

  • ux-notify: Mercure pushes native OS notifications instead of page updates
  • ux-native: Hotwire Native apps built on Turbo
  • ux-pagination: paginate inside a <turbo-frame> to update only the results
  • ux-map: maps reconnect after frame swaps
  • ux-icons: inline SVG icons survive Drive navigation and frame swaps
Files (symfony-ux-skills)
  • references
    • api.md 16.7 KB
      Loading…
    • gotchas.md 12 KB
      Loading…
    • patterns.md 13.4 KB
      Loading…
  • SKILL.md 14.1 KB
    ---
    name: turbo
    description: 'Symfony UX Turbo: Turbo Frames for partial navigation and form submissions, Turbo Streams for multiple updates and Mercure broadcasts, and Turbo Drive for links and forms. Use for turbo-frame, turbo-stream, twig:Turbo, TurboFrame, TurboStreamResponse, turbo_stream_from and #[Broadcast].'
    license: MIT
    metadata:
      author: Simon André
      url: https://smnandre.dev
    ---
    
    # Turbo
    
    Hotwire Turbo provides SPA-like speed with server-rendered HTML, and leaves the JavaScript to the library. Three components work together:
    
    - **Drive**: Automatic AJAX navigation for all links and forms (zero config)
    - **Frames**: Scoped navigation that updates only one section of the page
    - **Streams**: Server-pushed DOM mutations (append, replace, remove, etc.)
    
    ## Decision Tree
    
    ```
    Need to update the page?
    +-- Full page navigation          -> Turbo Drive (automatic, already active)
    +-- Single section from user click -> Turbo Frame
    +-- Multiple sections from action  -> Turbo Stream (HTTP response)
    +-- Real-time from server/others   -> Turbo Stream (Mercure / SSE)
    ```
    
    ## Installation
    
    ```bash
    composer require symfony/ux-turbo
    ```
    
    That's it. Turbo Drive is active immediately: all links and forms become AJAX.
    
    ## Turbo Drive
    
    Automatic SPA-like navigation. Every `<a>` click and `<form>` submit is intercepted, fetched via AJAX, and the `<body>` is swapped. The browser URL and history update normally.
    
    ### Disabling for Specific Elements
    
    ```html
    <!-- Disable on link/form -->
    <a href="/external" data-turbo="false">External Link</a>
    
    <!-- Disable for entire section -->
    <div data-turbo="false">
        <a href="/normal">Normal link (no Turbo)</a>
    </div>
    ```
    
    ### History and Caching
    
    ```html
    <!-- Replace history instead of push -->
    <a href="/page" data-turbo-action="replace">Replace History</a>
    
    <!-- Force full reload when asset changes -->
    <link rel="stylesheet" href="/app.css" data-turbo-track="reload">
    <script src="/app.js" data-turbo-track="reload"></script>
    ```
    
    ## Turbo Frames
    
    Scope navigation to a section of the page. Links and forms inside a frame update only that frame's content. The rest of the page stays untouched.
    
    ### Basic Frame
    
    ```html
    <!-- Page with frame -->
    <turbo-frame id="messages">
        <h2>Messages</h2>
        <a href="/messages/1">View Message 1</a>  <!-- Updates only this frame -->
    </turbo-frame>
    
    <!-- /messages/1 response must contain a matching frame ID -->
    <turbo-frame id="messages">
        <h2>Message 1</h2>
        <p>Content here...</p>
        <a href="/messages">Back to list</a>
    </turbo-frame>
    ```
    
    The server response is a full HTML page, but Turbo extracts only the matching `<turbo-frame>` and swaps it in.
    
    ### Lazy Loading
    
    Load frame content asynchronously after the page renders:
    
    ```html
    <turbo-frame id="notifications" src="/notifications" loading="lazy">
        <p>Loading...</p>
    </turbo-frame>
    ```
    
    ### Target Another Frame
    
    A link inside one frame can update a different frame:
    
    ```html
    <turbo-frame id="sidebar">
        <a href="/item/1" data-turbo-frame="main-content">View Item</a>
    </turbo-frame>
    
    <turbo-frame id="main-content">
        <!-- Content replaced here -->
    </turbo-frame>
    ```
    
    ### Break Out of Frame
    
    Navigate the entire page from within a frame:
    
    ```html
    <turbo-frame id="modal">
        <a href="/dashboard" data-turbo-frame="_top">Go to Dashboard</a>
    </turbo-frame>
    ```
    
    ### Frame with Form
    
    Forms inside frames submit and update within that frame. For invalid POSTs, see the [form validation response examples](references/patterns.md#form-validation-errors).
    
    ```html
    <turbo-frame id="search-results">
        <form action="/search" method="get">
            <input type="search" name="q">
            <button>Search</button>
        </form>
        <ul>
            {% for item in results %}
                <li>{{ item.name }}</li>
            {% endfor %}
        </ul>
    </turbo-frame>
    ```
    
    ### URL Sync
    
    Update the browser URL when a frame navigates (useful for bookmarkable state):
    
    ```html
    <turbo-frame id="products" data-turbo-action="advance">
        <!-- Browser URL updates when this frame navigates -->
    </turbo-frame>
    ```
    
    ## Turbo Streams
    
    Update multiple DOM elements from a single server response. Eight actions available (`append`, `prepend`, `replace`, `update`, `remove`, `before`, `after`, `refresh`), each targeting elements by ID or CSS selector.
    
    ### Stream Actions
    
    ```html
    <turbo-stream action="append" target="messages">
        <template><div id="msg_1">New message</div></template>
    </turbo-stream>
    
    <turbo-stream action="prepend" target="messages">
        <template><div id="msg_0">First!</div></template>
    </turbo-stream>
    
    <turbo-stream action="replace" target="notification">
        <template><div id="notification">Updated!</div></template>
    </turbo-stream>
    
    <turbo-stream action="update" target="counter">
        <template>42</template>
    </turbo-stream>
    
    <turbo-stream action="remove" target="msg_5"></turbo-stream>
    
    <turbo-stream action="before" target="msg_3">
        <template><div id="msg_2">Inserted before</div></template>
    </turbo-stream>
    
    <turbo-stream action="after" target="msg_3">
        <template><div id="msg_4">Inserted after</div></template>
    </turbo-stream>
    
    <turbo-stream action="refresh"></turbo-stream>
    ```
    
    `replace` and `update` support an optional `method="morph"` attribute for smooth DOM morphing instead of full replacement:
    
    ```html
    <turbo-stream action="replace" method="morph" target="user-card">
        <template><div id="user-card">Updated content</div></template>
    </turbo-stream>
    ```
    
    ### Target Multiple Elements (CSS Selector)
    
    Use `targets` (plural) with a CSS selector to affect multiple elements:
    
    ```html
    <turbo-stream action="remove" targets=".notification.read"></turbo-stream>
    
    <turbo-stream action="update" targets=".price">
        <template>99.00 EUR</template>
    </turbo-stream>
    ```
    
    ### Twig Component Syntax for Streams
    
    Use the `<twig:Turbo:Stream:*>` components instead of raw HTML:
    
    ```twig
    <twig:Turbo:Stream:Append target="#comments">
        {{ include('comment/_comment.html.twig') }}
    </twig:Turbo:Stream:Append>
    
    <twig:Turbo:Stream:Update target="#comment-count">
        {{ count }}
    </twig:Turbo:Stream:Update>
    
    <twig:Turbo:Stream:Remove target="#msg_5" />
    ```
    
    The component's `target` prop is rendered as `targets`, a CSS selector: prefix ids with `#`.
    
    ## Symfony Integration
    
    ### Stream Response from Controller
    
    ```php
    use Symfony\UX\Turbo\TurboBundle;
    
    #[Route('/messages', name: 'message_create', methods: ['POST'])]
    public function create(Request $request): Response
    {
        $message = new Message();
        // ... handle form
    
        $this->em->persist($message);
        $this->em->flush();
    
        // Only Turbo asks for the stream format: other clients get a redirect
        if (TurboBundle::STREAM_FORMAT === $request->getPreferredFormat()) {
            $request->setRequestFormat(TurboBundle::STREAM_FORMAT);
    
            return $this->render('message/create.stream.html.twig', [
                'message' => $message,
                'count' => $this->messages->count([]),
            ]);
        }
    
        return $this->redirectToRoute('message_index', status: Response::HTTP_SEE_OTHER);
    }
    ```
    
    You can also use the `TurboStreamResponse` helper or `TurboStream` helper methods for programmatic stream building.
    
    ### Stream Template
    
    ```twig
    {# templates/message/create.stream.html.twig #}
    <turbo-stream action="append" target="messages">
        <template>
            {{ include('message/_message.html.twig', {message: message}) }}
        </template>
    </turbo-stream>
    <turbo-stream action="update" target="message-count">
        <template>{{ count }}</template>
    </turbo-stream>
    <turbo-stream action="replace" target="new-message-form">
        <template>
            {{ include('message/_form.html.twig', {message: null}) }}
        </template>
    </turbo-stream>
    ```
    
    ### Detect Frame Request
    
    Since Symfony UX 3.1+, inject the `TurboFrame` service instead of reading the `Turbo-Frame` header by hand:
    
    ```php
    use Symfony\UX\Turbo\TurboFrame;
    
    #[Route('/task/{id}', name: 'app_task_show', methods: ['GET'])]
    public function show(TurboFrame $turboFrame, Task $task): Response
    {
        if ($turboFrame->isFrameRequest()) {
            $frameId = $turboFrame->getRequestId(); // e.g. "task_details"
            // Render a partial response (or a full page -- Turbo extracts the frame)
        }
    
        return $this->render('task/show.html.twig', ['task' => $task]);
    }
    ```
    
    The same check is available in Twig:
    
    ```twig
    {% if turbo_is_frame_request() %}
        <p>Frame ID: {{ turbo_frame_request_id() }}</p>
    {% endif %}
    ```
    
    To skip the full page layout in frame responses, extend `@Turbo/layouts/frame.html.twig`: see [references/api.md](references/api.md#minimal-frame-layout).
    
    ### Mercure Broadcasts (Real-time)
    
    Requires `symfony/mercure-bundle` and a Mercure hub. Push changes to all connected browsers via SSE. Since Symfony UX 3.1+, subscribe a page with `<twig:Turbo:Stream:From>` (requires `symfony/ux-twig-component`) or the `turbo_stream_from()` function, which renders a `<turbo-mercure-stream-source>` element:
    
    ```twig
    {# Subscribe to a string topic #}
    <twig:Turbo:Stream:From topics="chat" />
    
    {# Private topic (sends credentials with the EventSource) #}
    <twig:Turbo:Stream:From topics="chat" private />
    
    {# Same thing with the function #}
    {{ turbo_stream_from('chat', private: true) }}
    ```
    
    Publish to that topic from a controller with `HubInterface::publish(new Update('chat', $html))`, where `$html` is a rendered stream template.
    
    To broadcast Doctrine entity changes, add `#[Broadcast]` and subscribe to the entity or its class:
    
    ```php
    // src/Entity/Message.php
    namespace App\Entity;
    
    use Symfony\UX\Turbo\Attribute\Broadcast;
    
    #[ORM\Entity]
    #[Broadcast]
    class Message
    {
        // Creations, updates and deletions are broadcast automatically
    }
    ```
    
    Subscribe to one entity or to the whole class:
    
    ```twig
    {# Updates of one entity #}
    {{ turbo_stream_from(message) }}
    
    {# Every entity of the class (escape the backslashes) #}
    <twig:Turbo:Stream:From topics="App\\Entity\\Message" />
    
    <div id="messages">
        {# Messages appear here in real-time #}
    </div>
    ```
    
    - `#[Broadcast]` publishes to a topic derived from the entity class and id: subscribe with the class name (double the backslashes), or with an entity for that entity's updates only (`{{ turbo_stream_from(message) }}`).
    - Each change renders `templates/broadcast/Message.stream.html.twig`: it must define the `create`, `update` and `remove` blocks, and receives `entity`, `id`, `action` and the `#[Broadcast]` options.
    - For updates you publish yourself with `HubInterface::publish()`, subscribe to the same topic: `<twig:Turbo:Stream:From topics="chat" />`.
    
    ## Common Patterns
    
    ### Inline Edit
    
    ```html
    <!-- Display mode -->
    <turbo-frame id="task_{{ task.id }}">
        <span>{{ task.title }}</span>
        <a href="/tasks/{{ task.id }}/edit">Edit</a>
    </turbo-frame>
    
    <!-- Edit mode (response from /tasks/1/edit) -->
    <turbo-frame id="task_1">
        <form action="/tasks/1" method="post">
            <input name="title" value="Task title">
            <button>Save</button>
            <a href="/tasks/1">Cancel</a>
        </form>
    </turbo-frame>
    ```
    
    ### Modal in Frame
    
    ```html
    <turbo-frame id="modal"><!-- Empty by default --></turbo-frame>
    
    <a href="/items/1/delete" data-turbo-frame="modal">Delete</a>
    
    <!-- /items/1/delete response -->
    <turbo-frame id="modal">
        <dialog open>
            <p>Confirm delete?</p>
            <form method="post">
                <button>Delete</button>
            </form>
            <a href="/items" data-turbo-frame="modal">Cancel</a>
        </dialog>
    </turbo-frame>
    ```
    
    ### Flash Messages with Stream
    
    ```twig
    <turbo-stream action="prepend" target="flash-messages">
        <template>
            <div class="alert alert-success" role="alert">
                Item saved successfully!
            </div>
        </template>
    </turbo-stream>
    ```
    
    ## Key Principles
    
    **Server returns full HTML pages.** Turbo works best when the server always returns a complete, valid HTML page. Turbo Drive replaces the body, Turbo Frames extract the matching frame. Don't try to return partial HTML snippets (except for Stream templates).
    
    **Frame IDs must match.** The frame in the response must have the same `id` as the frame on the page. If they don't match, Turbo shows an error.
    
    **Streams are for side effects.** Use Streams when a single action needs to update multiple unrelated parts of the page. If you're only updating one section, a Frame is simpler.
    
    **Stimulus complements Turbo.** Turbo handles navigation and server communication. Stimulus handles client-side behavior (animations, toggles, clipboard). They work together: Stimulus controllers survive Turbo Frame swaps within their scope, and reconnect properly on Drive navigation.
    
    ## References
    
    - [Symfony UX package page](https://ux.symfony.com/turbo) ([Markdown summary](https://ux.symfony.com/turbo.md)) · [`symfony/ux-turbo` on Packagist](https://packagist.org/packages/symfony/ux-turbo).
    - For Drive, Frames, Streams and Symfony broadcasting, see the [Symfony UX Turbo documentation](https://symfony.com/bundles/ux-turbo).
    - For frame targeting and navigation attributes, see the [Hotwire Turbo Frames reference](https://turbo.hotwired.dev/reference/frames).
    - **Full API** (Drive events, Frame attributes, Stream actions, Mercure): [references/api.md](references/api.md)
    - **Patterns** (forms, modals, search, pagination, infinite scroll): [references/patterns.md](references/patterns.md)
    - **Gotchas** (caching issues, form handling, Stimulus integration): [references/gotchas.md](references/gotchas.md)
    
    ### Demos
    
    - Package page: [Drive navigation and form submission](https://ux.symfony.com/turbo#drive), [Frames to-do list](https://ux.symfony.com/turbo#frames), [Streams chat](https://ux.symfony.com/turbo#turbo-streams).
    - [Infinite scroll with Turbo Streams](https://ux.symfony.com/demos/turbo/infinite-scroll) and [infinite scroll with lazy Turbo Frames](https://ux.symfony.com/demos/turbo/infinite-scroll-2).
    - [Upload with Turbo](https://ux.symfony.com/demos/upload/turbo) submits a gallery from a Frame and appends it with a Stream.
    - [UX Inspector](https://ux.symfony.com/inspector#demo) shows Turbo Frames and tracks their activity.
    
    ## See Also
    
    - **ux-notify**: Mercure pushes native OS notifications instead of page updates
    - **ux-native**: Hotwire Native apps built on Turbo
    - **ux-pagination**: paginate inside a `<turbo-frame>` to update only the results
    - **ux-map**: maps reconnect after frame swaps
    - **ux-icons**: inline SVG icons survive Drive navigation and frame swaps
    

Comments

Sign in to join the conversation.

No comments yet. Start the conversation.

Reviews (0)

No reviews yet.