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

How in the world do I implement this?

Go to End

5 Posts   1012 Views


Community Member, 108 Posts

2 May 2009 at 10:32am

Okay, I've been up awhile and my brian is a little slow, however I must be missing something on the scale of Cloverfield.

I would like to implement this:

Where do you put the javascript to get executed? Where does the Requirements::javascript get put?

It seems so very simple to implement but it has taken me the better part of today to get even broken.

Any hep would be so appreciated.



Forum Moderator, 5523 Posts

2 May 2009 at 11:48am

Hey Terry,

On the page type you would like to add the JS (or if its on every page) just put Requirements::javascript( - link to file - ); for each JS file you need to include in the function init() in the Controller of the page. If you need to load a CSS file you can use Requirements::css()

Confused? Maybe an example will help. This is what we use in the forum to load custom JS and CSS

class ForumHolder_Controller extends Page_Controller {

	function init() {
		Requirements::themedCSS('Forum'); // loads themes/your_theme/css/Forum.css
		parent::init(); // you must have this line


Community Member, 108 Posts

2 May 2009 at 12:43pm


Thanks a million for this.

I know it's simple, but I must be missing something.

I have in my Page.php the following:

class Page_Controller extends ContentController {

public function init() {

//Sifr::add_font('trade', 'themes/rittheme/fonts/tradegothic.swf');
// Note: you should use SS template require tags inside your templates
// instead of putting Requirements calls here. However these are
// included so that our older themes still work

Requirements::javascript( "mysite/javascript/jquery.js" );
Requirements::javascript( "mysite/javascript/jquery.lightbox.js" );


It doesn't fire. I did the ?flush=1 I basically did exactly what the lightbox2 code has and it looks correct when I view source. Weird.

here's my page... Is there something I'm missing?


PS. I really appreciate you helping out on this.


Forum Moderator, 5523 Posts

2 May 2009 at 8:18pm

Have you got the firebug plugin for firefox? its essential for doing any sort of webdevelopment work. One thing it shows is the JS error console, and the errors on a page. If your sites case I can see it has 1 error - $(document).ready is not a function - so it seems like maybe how this is implemented is incorrect or maybe the prototype code SS has is conflicting. See for an example jquery file and try that


Community Member, 108 Posts

3 May 2009 at 3:23pm

Yes....Thank you willr.

I got it to work.

I so appreciate you helping everyone out. This is going to make the client exceedingly happy. Plus, it opens up SS to all kinds of jquery utilities.

Thanks again,