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:

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   1258 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 :)