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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Requirements::javascript loading js files twice


Go to End


6 Posts   2483 Views

Avatar
tv

Community Member, 44 Posts

18 July 2011 at 2:45am

I am trying to use Requirements::javascript to load in my .js files. For some reason silverstripe is loading all the files twice any time I use Requirements::javascript.

Has anyone else experienced this?

Here is my code:

function init() {
$themePath = 'themes/' . SSViewer::current_theme() . '/';
Requirements::javascript($themePath . 'js/JAIL.js');

parent::init();
}

I'm getting the same result when I try to use Requirements in page.php as well.

Thanks!

Avatar
swaiba

Forum Moderator, 1899 Posts

19 July 2011 at 4:39am

2 things to try...

1) move the parent::init to the beginning of the function
2) add a Debug::show('test') to ensure that the code is only called once

Avatar
swaiba

Forum Moderator, 1899 Posts

19 July 2011 at 4:39am

2 things to try...

1) move the parent::init to the beginning of the function
2) add a Debug::show('test') to ensure that the code is only called once

Avatar
tv

Community Member, 44 Posts

19 July 2011 at 9:18am

thanks swaiba.

I added a Debug test and it seemed to confirm that Page_Controller was only being called once. I also added the parent::init call at the top of the function, but still having the same issue. Any files inserted into the page through the Requirements::javascript method are being added twice - Requirements::customScript, Requirements::javascript, etc. Oddly, Requirements::css is not exhibiting the same behavior.

All other elements of my footer are only being inserted once (</body>, </html>, etc) so I don't think it is a matter of including my Footer twice.

Any other thoughts?

Thanks again!

Avatar
tv

Community Member, 44 Posts

21 July 2011 at 2:21am

Oddly enough, I removed my html5 <header> element in my header and replaced it <div id="header"> and that stopped the double inclusion of Requirements::javascript files.

Avatar
Innovatif

Community Member, 4 Posts

23 December 2011 at 5:27am