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.

Data Model Questions

[Solved] Conditional javascript include


Reply

3 Posts   2439 Views

Avatar
NickJacobs

30 April 2009 at 4:04pm (Last edited: 30 April 2009 9:41pm), Community Member, 144 Posts

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 **********

   
   }

Avatar
ajshort

30 April 2009 at 8:29pm Community Member, 244 Posts

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.

Avatar
NickJacobs

30 April 2009 at 9:41pm Community Member, 144 Posts

Perfect! thanks