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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Data Model Questions /

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

[Solved] Conditional javascript include


Go to End


3 Posts   2891 Views

Avatar
NickJacobs

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

30 April 2009 at 9:41pm

Perfect! thanks