Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

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.

Template Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

3rd party javascript


Go to End


3 Posts   1747 Views

Avatar
ssguest

Community Member, 7 Posts

15 August 2015 at 6:31am

Edited: 15/08/2015 6:32am

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?

Avatar
helenclarko

Community Member, 166 Posts

17 August 2015 at 4:31pm

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

Avatar
Pyromanik

Community Member, 419 Posts

17 August 2015 at 11:57pm

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).