Skip to content

[Live] Adding a custom Stimulus controller to a live component #527

Closed
@weaverryan

Description

@weaverryan

Sometimes you'll want to attach a stimulus controller to the root element of your live controller. Currently, you might try this:

<div
    {{ attributes.defaults({ 'data-controller: 'foo'})
>

But, I don't think that works, as I think we're always setting data-controller to live:

Also, that's a pretty ugly syntax, especially if you need to pass in some values 😱 .

What about one of the following:

<div
    {{ attributes.stimulusController('foo', {}) }]

    {{ stimulus_controller('foo', {})|attributes }}

    Is this one even possible? Would `|merge` instead of "+" work?
    {{ stimulus_controller('foo', {}) + attributes }}
>

stimulus_controller returns a StimulusControllersDto which has a toArray() method.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugBug Fix

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions