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:

Archive /

Our old forums are still available as a read-only archive.

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

how add javascript file

Go to End

5 Posts   6860 Views


Community Member, 87 Posts

7 October 2008 at 11:26pm

I try to modify menu of qa download tempate and to do this I need javascript I have:

chrome.css file that include css related to the menu
chromejs directory that include chrome.js file whit javascript code

The theme directory is caracterized by 3 folder:

so where I put my file?
I put chrome.css in css folder and chromejs in template (here there is where I call chrome.js in this way:
<script type="text/javascript" src="chromejs/chrome.js">

Then in, in the standar div I add

<div class="chromestyle" id="chromemenu" id="Navcontainer">
<% include Navigation %>

What is wrong?


Community Member, 470 Posts

8 October 2008 at 5:48am

Have you flushed the template cache afterward by visiting the page URL you're modifying and adding ?flush=1 to the end of it? i.e

Another way is to add it in the controller of the page type -


Community Member, 87 Posts

8 October 2008 at 7:47pm

Yes, I use correctly ?flush. I try also the second solution but something is wrong, why?


Forum Moderator, 922 Posts

8 October 2008 at 8:12pm

Edited: 08/10/2008 8:15pm

The best way to add your CSS and Javascript is using Requirements::themedCSS() for CSS, and Requirements::javascript() for Javascript on the init() methods for your controllers.

e.g. in Page.php

class Page extends SiteTree {

class Page_Controller extends ContentController {

	function init() {

		Requirements::javascript('themes/' . SSViewer::current_theme() . '/javascript/jquery-1.2.6.pack.js');


Make sure you have your theme directory structure like this:

- themes
- blackcandy
- css
- javascript
- templates
- mytheme
- css
- templates

Make sure that in order to use "mytheme", for example, you change the SSViewer::set_theme() to SSViewer::set_theme('mytheme') inside mysite/_config.php

Hope this helps!



Community Member, 87 Posts

10 October 2008 at 2:17am

Sorry but I have problem:
my file are chrome.js and chromestyle.css

I insert chrome.js in theme/mytheme/javascript and chromestyle.css in theme/css.

then in mysite/code/Page.php and tutorial/code/Page.php I add

Requirements::javascript('themes/' . SSViewer::current_theme() . '/javascript/chrome.js');

What is wrong?nothing seems go well.