Extending JS class - please help!

Hey there.
I want to extend the JS class, and need access to the referenced file, which (I guess) would be something like this:

$stuff = new Asset($src)

or does $src already ‘contain’ the file?

Question 2:
I’d like to extract some info from the file (eg hash it) and then save the output as new script $attr. What’s preferable: extending component/JS with: class MyCustomJSComponent extends Kirby\Component\JS { /* code goes here */ } (I’d like to assign a new name to my function, but buildin on JS component functionality) by merging my new attribute with the $attr array?

And furthermore, how can I achieve this while preserving the @auto functionality / array-wise insertion of multiple assets, adding my custom attribute to each generated script tag?

It’s not clear to me what you want to achieve, but if you want to override the default JS component, the Cachebuster plugin is a good example that may help you figure it out.

1 Like

Thanks for the starting point, I see where this goes.
What about naming it differently, so the handler doesn’t go <?= js('path/to/file') ?> but something like jsHashed('path/to/file')?

You can just create the jsHashed PHP function in a plugin file and replace it on you templates/snippets.