V3 → V4 migration: where should I put my item-tweaking JS?

CMS Version

4.3.0

Player Type

Player Version

Issue

In V3 we relied heavily on dataset tickers and custom HTML/CSS/JS. A common pattern was a bit of JS that looped through the rendered rows to hide repeating values, etc.

Now in V4 I built a “Dataset Custom HTML” template which enables the HTML/CSS/JS. Catch: the JS in that template runs before the items are actually rendered, so the old “iterate-and-tweak” code no longer works.

I can move the JS into onTemplateVisible of the template, and that does run after render, but every small change means cloning yet another template → we’d end up with dozens of them. Not maintainable.

Question
Is there a clean way to attach JS directly to the layout/widget itself so it fires after the dataset items are on-screen and can still manipulate them?

Thanks!