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, biapar, Willr, Ingo, swaiba, simon_w

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


3 Posts   471 Views


4 March 2012 at 5:20pm Community Member, 23 Posts


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?



4 March 2012 at 8:43pm Forum Moderator, 474 Posts

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


5 March 2012 at 11:49am Community Member, 23 Posts

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