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


Reply

8 Posts   3496 Views

Avatar
deLisle

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

Hi.

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 Page.ss file.

Any ideas?

Avatar
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.

Avatar
deLisle

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.

Avatar
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?

Avatar
Ingo

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 :)

Avatar
deLisle

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

Yeah, what Ingo said. :)

Avatar
Carbon Crayon

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

ahh ok.....no idea then! :)

Avatar
Markiv

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() {
      parent::init();

      
      Requirements::javascript("themes/my-theme/js/jquery.js");
      Requirements::javascript("themes/my-theme/js/cufon-yui.js");
      Requirements::javascript("themes/my-theme/js/Avenir_Next_LT_Pro_500.font.js");
      Requirements::javascript("themes/my-theme/js/Avenir_Next_LT_Pro_600.font.js");
      Requirements::javascript("themes/my-theme/js/Adelle_Rg_italic_400.font.js");

   }

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">
      Cufon.replace('.block1-title');
      Cufon.replace('.news-title');
   </script>

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

plz any one help !!!

Thanks in advance