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 /

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

[Solved] Conditional javascript include


Go to End
Reply


3 Posts   2640 Views

Avatar
NickJacobs

Community Member, 146 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, 146 Posts

30 April 2009 at 9:41pm

Perfect! thanks