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.

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

[SOLVED] Requirements::javascript latches on to inline javascript

Go to End

3 Posts   845 Views


Community Member, 23 Posts

4 March 2012 at 5:20pm


I'm using 2.4.6. Normally the javascript appears at the bottom of the document. But I noticed an odd thing with a HTML page that has some inline javascript. The javascript files included via the Requirements::javascript() - called in the Page_Controller::init() - end up inserted just before my last piece of inline javascript. Certainly not what I was expecting. To work around this I have used the flag Requirements::set_write_js_to_body(false) in _config.php to force the javascript to the top. Note: the javascript is being generated inline by a PHP method. Expected behaviour or bug?



Community Member, 473 Posts

4 March 2012 at 8:43pm

That's expected as there's no way to know if the inline javascript relies on something being included or not.


Community Member, 23 Posts

5 March 2012 at 11:49am

That shows my lack of web dev. experience! Thanks Simon.