Jump to:

23371 Posts in 18161 Topics by 2865 members

General Questions

SilverStripe Forums » General Questions » How in the world do I implement this?

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 741 Views
  • TerryMiddleton
    Avatar
    Community Member
    108 Posts

    How in the world do I implement this? Link to this post

    Okay, I've been up awhile and my brian is a little slow, however I must be missing something on the scale of Cloverfield.

    I would like to implement this: http://www.lokeshdhakar.com/projects/lightbox2/

    Where do you put the javascript to get executed? Where does the Requirements::javascript get put?

    It seems so very simple to implement but it has taken me the better part of today to get even broken.

    Any hep would be so appreciated.

    Terry

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: How in the world do I implement this? Link to this post

    Hey Terry,

    On the page type you would like to add the JS (or if its on every page) just put Requirements::javascript( - link to file - ); for each JS file you need to include in the function init() in the Controller of the page. If you need to load a CSS file you can use Requirements::css()

    Confused? Maybe an example will help. This is what we use in the forum to load custom JS and CSS

    ...
    class ForumHolder_Controller extends Page_Controller {

       function init() {
          Requirements::themedCSS('Forum'); // loads themes/your_theme/css/Forum.css
          Requirements::javascript("jsparty/jquery/jquery.js");
          Requirements::javascript("forum/javascript/jquery.MultiFile.js");
          Requirements::javascript("forum/javascript/forum.js");
          parent::init(); // you must have this line
       }
    ...

  • TerryMiddleton
    Avatar
    Community Member
    108 Posts

    Re: How in the world do I implement this? Link to this post

    willr,

    Thanks a million for this.

    I know it's simple, but I must be missing something.

    I have in my Page.php the following:

    class Page_Controller extends ContentController {
       
       public function init() {
          
          //Sifr::add_font('trade', 'themes/rittheme/fonts/tradegothic.swf');
          Sifr::replaceElement(".Title","SolexMinLin",'sColor:"#007CA8",sLinkColor:"#fe6e0e",sHoverColor:"#fe6e0e"');
          Sifr::loadSifr();
          // 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::themedCSS("lightbox");
          
          Requirements::javascript( "mysite/javascript/jquery.js" );
          Requirements::javascript( "mysite/javascript/jquery.lightbox.js" );
          
          parent::init();
       }

    It doesn't fire. I did the ?flush=1 I basically did exactly what the lightbox2 code has and it looks correct when I view source. Weird.

    here's my page... Is there something I'm missing?

    http://63.247.208.15/dose-calibration/

    Terry

    PS. I really appreciate you helping out on this.

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: How in the world do I implement this? Link to this post

    Have you got the firebug plugin for firefox? its essential for doing any sort of webdevelopment work. One thing it shows is the JS error console, and the errors on a page. If your sites case I can see it has 1 error - $(document).ready is not a function - so it seems like maybe how this is implemented is incorrect or maybe the prototype code SS has is conflicting. See http://doc.silverstripe.com/doku.php?id=jquery for an example jquery file and try that

  • TerryMiddleton
    Avatar
    Community Member
    108 Posts

    Re: How in the world do I implement this? Link to this post

    Yes....Thank you willr.

    I got it to work.

    I so appreciate you helping everyone out. This is going to make the client exceedingly happy. Plus, it opens up SS to all kinds of jquery utilities.

    Thanks again,

    Terry

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