Jump to:

3373 Posts in 998 Topics by 712 members

Data Model Questions

SilverStripe Forums » Data Model Questions » [Solved] Conditional javascript include

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

Page: 1
Go to End
Author Topic: 2375 Views
  • NickJacobs
    Avatar
    Community Member
    144 Posts

    [Solved] Conditional javascript include Link to this post

    The jquery stuff I include in my site breaks the contact form validation, so I want to try to do a conditional include in the Page_Controller. Is there any way of doing something like:

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

          ***if ClassName !="UserDefinedForm" then***

          Requirements::javascript("jsparty/jquery/jquery.js");
          Requirements::javascript("mysite/javascript/cyclelite.js");
          Requirements::javascript('mysite/javascript/misc.js');

    ***** end_if **********

       
       }

  • ajshort
    Avatar
    Community Member
    244 Posts

    Re: [Solved] Conditional javascript include Link to this post

    Something like:

    public function init() {
       if($this->ClassName != 'UserDefinedForm') {
          Requirements::javascript('jsparty/jquery/jquery.js');
          Requirements::javascript('mysite/javascript/cyclelite.js');
          Requirements::javascript('mysite/javascript/misc.js');
       }
       
       parent::init();
    }

    should do what your after I think.

  • NickJacobs
    Avatar
    Community Member
    144 Posts

    Re: [Solved] Conditional javascript include Link to this post

    Perfect! thanks

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