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

Custom javascript with additional page types problem

Go to End

4 Posts   1523 Views


Community Member, 165 Posts

27 July 2009 at 12:36am

Hello, first of all what an amazing CMS Silverstripe is! When is the book due for release?

I have a small problem with a site I'm building at the moment. I have some custom css and javascript I'm running for some progressive enhancements on my navigation.

The trouble is that when I use a page type other than the default 'Page' it is not picking up the extra javascript files.

This is what my Page.php looks like:

class Page_Controller extends ContentController {

public function init() {


Am I right to say that any other page types you create as long as you specify:

class ContactPage_Controller extends Page_Controller{

...should inherit the default Page type classes for requirments? It seems to pick up the css but not the javascript files.

One more thing, I've come this far and this my first time developing with Silverstripe. I'm a bit confused however as to how I write my paths, as you will see above I have written the absolute path to get working results, when trying relative it simply doesn't work. What am I doing wrong here? Need to know for when I go live with this beast!


Forum Moderator, 5523 Posts

27 July 2009 at 5:10pm

All paths are usually relative from your root domain or root SS folder (depending on where you are talking about) So..

Requirements::javascript("themes/yourtheme/javascript/afile.js"); will point to that path.

ThemedCSS is a shortcut to themes/yourtheme/css so Requirements::themedCSS("layout"); is the same as Requirements::css("themes/yourtheme/css/layout.css"). Currently themedJavascript() does not exist which is why for JS you have to use the path like above.

...should inherit the default Page type classes for requirments? It seems to pick up the css but not the javascript files.

Correct. It should pickup the JS files aswell. Update your code to the proper relative path and try again. Make sure also that the JS isn't just loaded to the bottom of the page (which SS does for performance)


Community Member, 165 Posts

28 July 2009 at 8:39am

Edited: 28/07/2009 8:41am

Will, thanks for the reply

Yes you are right, the javascript files are all at the bottom of the page. How can I make these sit in the head tag?

Also, I am only using jquery, is there a way for me to turn off the other libraries?



Community Member, 165 Posts

28 July 2009 at 9:26am

Edited: 28/07/2009 9:35am

I have now sorted out my problem

Thanks for the advice