addJs with parameter

Hey there,

After an update of October cms to version 2.2.15 the addJs method seems to ignore the added parameters. The documentation says:

public void addJs($name, $attributes=array())

Is this attributes argument for adding parameters?

I have this code here:

$this->addJs('assets/js/multi_captcha.js', http_build_query($params));

The outcome then looks like this:

<script src="https://example.com/plugins/vijaywilson/multicaptcha/assets/js/multi_captcha.js"></script>

Unfortunately, there aren’t any parameters added here. What can I do better?

UPDATE: The $params by the way is an array. It is build like that:

$params = [
    'site-key' => (isset($multicaptcha['site_key'])) ? $multicaptcha['site_key'] : '',
    'locale' => $locale
];

Hi! The $attributes property is not for the query string. It is used for html element attributes.

Example

$this->addJs('assets/js/app.js', ['defer' => true])

Outputs to:

<scripts defer="true" src="https://example.com/.../assets/js/app.js"></script>

If you want to add query parameters try this:
'assets/js/multi_captcha.js?' . http_build_query($params)

2 Likes