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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Archive /

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

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

Include a widget on all pages


Go to End


2 Posts   1868 Views

Avatar
teejay

Community Member, 63 Posts

24 July 2008 at 8:59am

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

Avatar
teejay

Community Member, 63 Posts

24 July 2008 at 4:27pm

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