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.

Archive /

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

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

Include a widget on all pages


Reply


2 Posts   1588 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