Jump to:

3435 Posts in 1026 Topics by 866 members

Template Questions

SilverStripe Forums » Template Questions » Requirements::javascript can't load my js file

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 3424 Views
  • deLisle
    Avatar
    Community Member
    12 Posts

    Requirements::javascript can't load my js file Link to this post

    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?

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: Requirements::javascript can't load my js file Link to this post

    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.

  • deLisle
    Avatar
    Community Member
    12 Posts

    Re: Requirements::javascript can't load my js file Link to this post

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

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: Requirements::javascript can't load my js file Link to this post

    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?

  • Ingo
    Avatar
    Forum Moderator
    801 Posts

    Re: Requirements::javascript can't load my js file Link to this post

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

  • deLisle
    Avatar
    Community Member
    12 Posts

    Re: Requirements::javascript can't load my js file Link to this post

    Yeah, what Ingo said.

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: Requirements::javascript can't load my js file Link to this post

    ahh ok.....no idea then!

  • Markiv
    Avatar
    Community Member
    2 Posts

    Re: Requirements::javascript can't load my js file Link to this post

    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

    3424 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.