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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

check for widgets in template


Go to End


3 Posts   1488 Views

Avatar
marcink

Community Member, 89 Posts

23 March 2009 at 9:08am

hi,

i only want to include the sidebar template, when i have assigned a widget to a page...

now i only have an include statement <% include Sidebar %> in my templates. how can i check if i have to include the sidebar or not?

thanks

Avatar
Double-A-Ron

Community Member, 607 Posts

25 March 2009 at 5:41pm

I do this with one of my custom page types by adding a checkbox to the "Behaviours" tab in the CMS.

CustomPage.php

class CustomPage extends Page {

	static $db = array(
		'DisplaySidebar' => 'Boolean'
	);
	
	static $defaults = array(
		'DisplaySidebar' => true
	);

function getCMSFields() {
$fields->addFieldToTab( 'Root.Behaviour', new CheckboxField('DisplaySidebar', 'Display Sidebar?') );
}
}

Then in my template:

<% if DisplaySidebar %>
         <% include Sidebar %>
<% end_if %>

Cheers
Aaron

Avatar
marcink

Community Member, 89 Posts

26 March 2009 at 8:21am

cool, thanks a lot. that helps :)