Same controllers with different data and elements


I call several times the same controller but i don’t have different data or element because it’s the same controller.

<div data-controller='slideshows'>
  <div data-controller='slideshow' data-slideshow-index="1">...</div>
  <div data-controller='slideshow' data-slideshow-index="4">...</div>

How to get the good element and the good data by controller ?

You can do something like this

<div data-controller='slideshows'>
  <div data-controller='slideshow' data-slideshow-index="1" data-action="click->slideshow#handleClick">...</div>
  <div data-controller='slideshow' data-slideshow-index="4" data-action="click->slideshow#handleClick">...</div>

and then in your controller

handleClick(event) {
1 Like