Jump to:

5539 Posts in 1738 Topics by 1224 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Inserting custom javascript

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

Page: 1 2
Go to End
Author Topic: 6451 Views
  • BelindaBJ
    Avatar
    Community Member
    9 Posts

    Inserting custom javascript Link to this post

    New to this, I'm on page.ss and I'm trying to add some dhtmlgoodies.com javascript for a slide-show, I have managed to use the <% require%> tags to include the css but the javascript isn't working for me, am I doing something wrong? I've tried it with and without the.js but neither are getting my slide show rolling???

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en" >

    <head>
          <% base_tag %>
          <title><% if MetaTitle %>$MetaTitle<% else %>$Title<% end_if %> &raquo; Your Site Name</title>
          $MetaTags(false)

          <link rel="shortcut icon" href="/favicon.ico" />
          

          <% require themedCSS(layout) %>
          <% require themedCSS(typography) %>
          <% require themedCSS(form) %>
          <% require themedCSS(sitetest) %>
          <% require themedCSS(image-slideshow) %>
          <% require javascript(themes/blackcandy/js/image-slideshow.js) %>

    Any clues greatly appreciated.

    Thanks.

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: Inserting custom javascript Link to this post

    Hi Belinda

    Try adding this function to your Page_Controller class:

       function init() {
          parent::init();
          Requirements::javascript("themes/blackcandy/js/image-slideshow.js");
       }

    I usually include all my files via the Controller as I find it cleaner and more intuitive. I know you can include CSS via the template, not sure about JS.

    Hope that helps

    Aram

  • BelindaBJ
    Avatar
    Community Member
    9 Posts

    Re: Inserting custom javascript Link to this post

    Thanks for your response, really appreciated.

    I tried adding all of what you suggested, and I got a blank page after a flush, so I have inserted just that line at the bottom and the page is loading, but the javascript isn't working. When I view source the include image-slideshow.js script isn't there anywhere?? If you have any other ideas I'd be a happy lady!

    class Page_Controller extends ContentController {
       
       public function init() {
          parent::init();

          // Note: you should use SS template require tags inside your templates
          // instead of putting Requirements calls here. However these are
          // included so that our older themes still work
          Requirements::themedCSS("layout");
          Requirements::themedCSS("typography");
          Requirements::themedCSS("form");
          Requirements::javascript("themes/blackcandy/js/image-slideshow.js");

       }

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: Inserting custom javascript Link to this post

    If the script isn't loading then it means SS hasn't found it, check that the path is correct.

  • BelindaBJ
    Avatar
    Community Member
    9 Posts

    Re: Inserting custom javascript Link to this post

    Thanks, I know it must be something like that, but even when I put the whole path in it's not showing up. Grrr

    class Page_Controller extends ContentController {
       

       public function init() {
          parent::init();

          // Note: you should use SS template require tags inside your templates
          // instead of putting Requirements calls here. However these are
          // included so that our older themes still work
          Requirements::themedCSS("layout");
          Requirements::themedCSS("typography");
          Requirements::themedCSS("form");
          Requirements::javascript("http://localhost:8888/silverstripe/themes/blackcandy/js/image-slideshow.js");
             
       }

  • banal
    Avatar
    Community Member
    901 Posts

    Re: Inserting custom javascript Link to this post

    Using the path as in your previous posts should work just fine.
    - Make sure the path is correct, eg. this file exists: themes/blackcandy/js/image-slideshow.js
    - If you're running *nix (that includes mac os x), check the permissions of the file.
    - Note, that the javascript file will be included at the bottom of the html code, just before the closing body tag (just in case you were looking at the wrong place...)

  • BelindaBJ
    Avatar
    Community Member
    9 Posts

    Re: Inserting custom javascript Link to this post

    Doh! Yes, I was looking in the wrong place, it was there. Still not working though. I am running Mac os x, how do I check the file permissions?

    Thank you.

  • banal
    Avatar
    Community Member
    901 Posts

    Re: Inserting custom javascript Link to this post

    Well, if it's there, the permissions are right. There must be an error in the script or something. Or maybe you simply forgot to initialize it? Firebug will help a great deal there (http://getfirebug.com/)

    6451 Views
Page: 1 2
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.