Hi,
I'm trying to use a 3rd party javascript but SIlverstripe seems not to find it even after putting the full path. Anybody knows how to set this up?
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
Hi,
I'm trying to use a 3rd party javascript but SIlverstripe seems not to find it even after putting the full path. Anybody knows how to set this up?
Hi ssguest,
I suggest having a look at the templates requirement guide.
This guide will help to add javascript as a requirement on either your templates or within your php.
https://docs.silverstripe.org/en/3.2/developer_guides/templates/requirements/
-helenclarko
It's helpful if you show an example of what you're doing when asking for help, as sometimes it's as simple as seeing the path in use.
For example we cannot tell from your post whether the third party script is hosted on your server, or on a CDN, etc.
If you're using requirements (which you should be - instead of hard coded script tags in the template) then it will not be included if SS cannot find the file. This could be your issue.
<script src="/path/to/somewhere/else.js"> won't work if your install is in a subfolder (and shouldn't be used anyway - see HelenClarko's post)
Requirements::javascript($script) requires that $script includes all the http:// and all if it's hosted externally. Simply "www.cdn.tld/thirdparty/script.js" wont' do.
<% require javascript() %> requires that you use quotes around the uri you supply (as per the docs).