Jump to:

794 Posts in 409 Topics by 304 members


SilverStripe Forums » Widgets » Widgets on a Page

Discuss SilverStripe Widgets.

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

Page: 1
Go to End
Author Topic: 606 Views
  • merrick_sd
    Community Member
    95 Posts

    Widgets on a Page Link to this post

    How can i tell if a Page has 'any' widgets?

    If a page has a widget the page will need a sidebar.


       public static $has_one = array(
       "MyWidgets" => "WidgetArea"      

    Layout >Page.ss

    <% if MyWidgets %>
    <!-- Widgets -->
    <!-- endWidgets -->
    <% else %>
    <!-- NO Widgets -->

    <% end_if %>

    On pages without widgets, no widgets show up as expected ...however the "if MyWidgets" isn't actually working! as the comment <!-- Widgets --> Always get rendered.

    maybe i need a fuction on Page.phpto do some kind of check.

    i want to do something like
    if widges show a menu <span class="span3"> ..etc

  • merrick_sd
    Community Member
    95 Posts

    Re: Widgets on a Page Link to this post

    Page_Controller ...
    //check if this page has widgets assigned to it!
       public function WidgetCheck() {
       $widgetid = $this->MyWidgetsID;
       $widgetdata = Widget::get()->filter(array('ParentID' => $widgetid));
          return $widgetdata;

    this works

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.