Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Include a widget on all pages

Our old forums are still available as a read-only archive.

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

Page: 1
Go to End
Author Topic: 1513 Views
  • teejay
    Avatar
    Community Member
    63 Posts

    Include a widget on all pages Link to this post

    Hi,

    I have got a question, about widgets. Is it possible to add a specific widget to all pages by default. I have have done a work around to do that, but this work around is code based so I have no influence on the behavior from the cms.

    I have included the following gode to the page model.

    static $has_one = array(
    "Sidebar" => "WidgetArea",
    );
    function getCMSFields() {
    $fields = parent::getCMSFields();
    $fields->addFieldToTab("Root.Content.Widgets", new WidgetAreaEditor("Sidebar"));
    return $fields;
    }

    and in the page controller I do the following

    public function Sidebar() {
    $w = new SidebarWidget();
    return $w->renderWith('SidebarWidget');
    }

    Now the widget is visible on all pages which inherits from page. The problem is that you have no influance on turning it on or off in the cms. Has anyone a idea to add a widget to all pages without it to all pages manually?

    Best regards
    Thomas

  • teejay
    Avatar
    Community Member
    63 Posts

    Re: Include a widget on all pages Link to this post

    Hmm I hope my english isn't so bad that nobody understands what I want to do. Anyway, I had a idea how to add a widget on all pages of a specific pagetype or all. Is it possible to create a page with a button for each widget (in the cms). If i click on a button a function will be called which adds for all pages the necessary inserts into the database.

    Hmm

    Regards Thomas

    1513 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.