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:

Widgets /

Discuss SilverStripe Widgets.

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

Using <% if $SideBarView %> in template

Go to End

3 Posts   1489 Views


Community Member, 2 Posts

20 January 2016 at 2:49pm

Edited: 20/01/2016 3:22pm

Not sure if this has been covered before, and Had tried to search the web. But I am looking at using the $SideBarView variable, especially when trying to determine a template layout, so for example:

<div class="col-<% if $SideBarView %>6<% else %>12<% end_if %>">

However, I am trying to use this at the base layout with no luck. Ideally I have a few different Layout templates to deal with so was wondering if anyone can point me in a good direction, to kind of determine in a more 'global' way of determining if the SideBar view should exist or not?


Community Member, 67 Posts

4 February 2016 at 4:48pm

Use the $Debug variable in the template to output useful info on the variables available.
Another thing to consider is that your template code may be inside a loop which means it may have gone out of scope


Community Member, 2 Posts

4 February 2016 at 5:09pm

Edited: 04/02/2016 5:10pm

Thanks for the suggestion. If anyone is interested, here is a current workaround:

class MyPageExtension extends DataExtension

 function HasSidebar()
        $sidebarID = $this->owner->SideBarID;
        if ($sidebarID) {
            $widgets = DataObject::get_one("Widget", "ParentID = $sidebarID");
            if ($widgets) {
                return $widgets;
        } else {
            return false;

so in the template file:

div class="w-col-<% if $hasSidebar %>6<% else %>12<% end_if %>">