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.

Form Questions /

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

js script inserted via Requirements::javascript doesn't work


Go to End


2 Posts   1458 Views

Avatar
robbie.munger

Community Member, 4 Posts

30 October 2013 at 10:17am

I have inherited a SilverStripe project that I am cleaning up. Ext JS is used and therefor included in multiple pages. I would like to load the script along with other common requirements in Page.php, as other pages inherit from here. In code I have

class Page_Controller extends ContentController {
	function init() {
		parent::init();
		Requirements::set_write_js_to_body(false);
		Requirements::javascript('mysite/javascript/extjs.js');

This produces in <head>

<script type="text/javascript" src="http://localhost/websitename/index.php/mysite/javascript/extjs.js?m=1259182671"></script>

but extjs.js doesn't seem to load, e.g. "flyout" menus depending on it don't appear

If I include extjs.js directly in code with

<script src="$ThemeDir/javascripts/extjs.js" type="text/javascript" charset="utf-8"></script>

this produces in <head>

<script src="/themes/websitename/javascripts/extjs.js" type="text/javascript" charset="utf-8"></script>

which does work.

Though I have a "workaround" I am trying to understand SilverStripe and http/html better. So I would like to understand the problem before deciding how to structure this site. Can someone explain the difference in behavior? Thanks!

Avatar
robbie.munger

Community Member, 4 Posts

30 October 2013 at 10:20am

I see I included from two different places. extjs.js is in both places and I have tested both ways. I plan to remove one copy as part of cleanup. This is typical of state of site. As in, I am still asking for help.