Skip to content

[LiveComponent] Make live_action compatible with Twig components #2586

@gremo

Description

@gremo

Right now, you cannot directly use the live_action helper to render live attributes because it returns a string. This means the following will not work:

<twig:Button type="button" {{ live_action("foo", { bar: "baz" }) }}>
  Click me!
</twig:Button>

On the other hand, some helpers like stimulus_controller and stimulus_action work because they return an iterable that can be used with the Twig spread operator .....

I don't if why this returns a string instead of the StimulusAttributes instance? What I'm missing?

This would be a great DX addition 👍

I changed LiveComponentRuntime to return the StimulusAttributes instance and the following will work without any problem:

<twig:Button
    type="button"
    content="Click me!"
    {{ ...live_action("foo", { bar: "baz" }) }}
/>

<button type="button" {{ live_action("foo", { bar: "baz" }) }}>
    Click me!
</div>

Metadata

Metadata

Assignees

No one assigned

    Labels

    LiveComponentRFCRFC = Request For Comments (proposals about features that you want to be discussed)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions