How to include external script?
-
@pitaj Maybe use the 'filter:scripts.get' hook?
-
I guess you're trying to include this in your plugins ACP page then...
In this case you just need to include it via
script
/style
-tag within your template. -
I've tried that as well. Shouldn't the URL of the script be
/plugins/nodebb-plugin-teamspeak/public/datetimepicker/jquery.datetimepicker.js
-
Well I figured out what I was doing wrong. Since I made the public directory public, I should have been putting
/plugins/nodebb-plugin-teamspeak/public/datetimepicker/jquery.datetimepicker.min.js
but I was leaving the public out
/plugins/nodebb-plugin-teamspeak/datetimepicker/jquery.datetimepicker.min.js
-
glad to hear and to make sure this works with each NodeBB configuration you'll have to use the client-side js-variable
RELATIVE_PATH
and prepend it to your path -
Why? What does that do? How would it help?
-
I thought only I did stuff like that
-
Within the config.json of your NodeBB installation you can set up a relative path to prepend all NodeBB URLs, so this would result in your files beeing accessed in
/relative/path/plugins/nodebb-plugin-teamspeak/public/datetimepicker/jquery.datetimepicker.min.js
I don't have a installation to make sure now but as far I remember this is the way it works... -
How would that help though? It seems like it's more complicated.
-
In which way should it be more complicated?
I've tested now. If you set
"relative_path": "/board"
you need to access /board/plugins/my-plugin/static/dir/path/file and the value ofRELATIVE_PATH
is"/board"
.So if the admin has set up correctly with the correct
base_url
anduse_port
,{relative_path}/plugins/nodebb-plugin-teamspeak/public/datetimepicker/jquery.datetimepicker.min.js
should give you the correct URL.EDIT: use the template-variable
{relative_path}
rather than js-tag -
But I could just access
plugins/my-plugin/static/dir/path/file
without the extra/board
and without configuring anything. What is the advantage of doing this? Freeing up url namespace? -
The advantage is that some admins don't want to have NodeBB at the root of their websites.
So they can do this by changing the config and NodeBB takes care of it.But if your plugin doesn't take care of this it'll be broken (at least the datetimepicker) for those installations.
-
Okay I understand.
-
Thanks for your help @frissdiegurke
-
haha @julian late to the party. As am I of course. Glad you guys figured it out
-
@julian I wasn't getting any errors when using the scripts property from the plugin.json. They simply weren't included on any of the admin pages.