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.

Template Questions

Requirements::javascript can't load my js file


8 Posts   3496 Views


14 March 2009 at 12:53am Community Member, 12 Posts


I've created a new Page type. The template for this page type i've put in the Layout folder.

Now when i try to add Requirements::javascript( 'myjsfile.js' ); I know it needs to be in function init in the controller.

It doesn't add it to my main file.

Any ideas?

Carbon Crayon

14 March 2009 at 2:02am Community Member, 598 Posts

Hi DeLisle, welcome to Silverstripe :)

You need to put the full path of your file in there, so something like:

Requirements::javascript( 'mysite/javascript/myjsfile.js' );

Silverstripe is smart in that if it doesn't find your file at the specified path it wont try to include it.


14 March 2009 at 2:07am Community Member, 12 Posts

Thanks for your reploy however,
i've alread tried adding the full path, it doesn't help.

Carbon Crayon

14 March 2009 at 2:23am Community Member, 598 Posts

hmm thats strange, it can only be one of two things, either the path is wrong on the innit function syntax is wrong, could you post your innit() code?


14 March 2009 at 2:28am Forum Moderator, 801 Posts

Andrew is using a heavily customized SSViewer implementation, so the problem is most likely not in SilverStripe core :)


14 March 2009 at 2:29am Community Member, 12 Posts

Yeah, what Ingo said. :)

Carbon Crayon

14 March 2009 at 2:36am Community Member, 598 Posts

ahh idea then! :)


21 April 2012 at 9:42pm Community Member, 2 Posts

i have placed my .js file in mysite/code/page.php ... like

   public function init() {



for now i need to Write some code like

   <script type="text/javascript" src="js/Avenir_Next_LT_Pro_500.font.js"></script>
   <script type="text/javascript">

how can i write code linke this... in siverstripe

plz any one help !!!

Thanks in advance