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.

Customising the CMS /

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

Adding external JavaScript


Go to End


7 Posts   3097 Views

Avatar
Victor

Community Member, 128 Posts

1 April 2009 at 9:23am

jsMath javascript suite is very useful for displaying math
On normal pages produced with this script in mind it is enough to add <script type="text/javascript" src="jsMath/jsMath.js">
How one can load some js on SilverStripe pages?

Thank you in advance. Victor

Avatar
Victor

Community Member, 128 Posts

3 April 2009 at 2:11pm

So, what is the way to add external javascript to CustomPage?

Thank you in advance

Victor

Avatar
t|m

Community Member, 19 Posts

10 April 2009 at 4:16pm

how about

Requirements::javascript("filejs");

Avatar
Victor

Community Member, 128 Posts

11 April 2009 at 7:46am

Well, I know this (and it should be enclosed into

public function init()
{

}

However it does not work in some particular case:

Compare

http://weyl.math.toronto.edu:8888/devsite/x.html

which shows properly parsed mathematical expression

with

http://weyl.math.toronto.edu:8888/devsite/test/?stage=Live

Avatar
bummzack

Community Member, 904 Posts

11 April 2009 at 10:39pm

Hi Victor

On the page where it works you have the following javascript statement: jsMath.Process();
Whereas on the SilverStripe site it's completely lacking...
You should probably add

Requirements::customScript('jsMath.Process();');

to your init method.
Some other file seems to be missing on the SilverStripe site as well. I get the following error in firebug:
uncaught exception: jsMath can't load the file 'http://weyl.math.toronto.edu:8888/devsite/test/jsMath-fallback-symbols.js' Error status: 404

Avatar
Victor

Community Member, 128 Posts

12 April 2009 at 12:23am

Well, it did not work this way but your post suggested me a different solution: instead of paste htm source in (html) in Content allowing to TinyMCE to handicap it, I created new HTMLText field and pasted html snippet with reference to javascript there

http://weyl.math.toronto.edu:8888/devsite/test/?stage=Live

PS Still I left reference to jsMath in .php, I suspect it is needed

Thanks! Victor

Avatar
BenWu

Community Member, 97 Posts

9 January 2013 at 1:18pm

how about

 LeftAndMain::require_javascript('mysite/javascript/initGoogleMaps.js')