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   2509 Views

Avatar
NickJacobs

Community Member, 144 Posts

30 April 2009 at 4:04pm

Edited: 30/04/2009 9:41pm

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

Community Member, 244 Posts

30 April 2009 at 8:29pm

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

Community Member, 144 Posts

30 April 2009 at 9:41pm

Perfect! thanks