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.

Widgets /

Discuss SilverStripe Widgets.

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

Using <% if $SideBarView %> in template


Go to End
Reply


3 Posts   1209 Views

Avatar
camex

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 Page.ss 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?

Avatar
Kirk

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

Avatar
camex

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 %>">