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.

General Questions /

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

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

check for widgets in template


Reply


3 Posts   1067 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, 604 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 :)