Jump to:

23491 Posts in 18996 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » check for widgets in template

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

Page: 1
Go to End
Author Topic: 1022 Views
  • marcink
    Avatar
    Community Member
    89 Posts

    check for widgets in template Link to this post

    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

  • Double-A-Ron
    Avatar
    Community Member
    604 Posts

    Re: check for widgets in template Link to this post

    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

  • marcink
    Avatar
    Community Member
    89 Posts

    Re: check for widgets in template Link to this post

    cool, thanks a lot. that helps

    1022 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.