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, biapar, Willr, Ingo, swaiba, simon_w

Inherit Widgets


Go to End
Reply


12 Posts   3508 Views

Avatar
tzeller

Community Member, 26 Posts

24 January 2009 at 1:12am

i am wondering if there is any possiblity that i can automatically inherit a widget from the parent to all children?

Avatar
Nivanka

Community Member, 395 Posts

24 January 2009 at 3:28pm

what do you mean? do you need to add a widget to all the pages or what?

Avatar
tzeller

Community Member, 26 Posts

25 January 2009 at 1:17am

i have added the widgets to all my pages (page.php and other modules such as ecommerce, etc.). i am on silverstripe 2.3 rc2.

And now instead of adding the widgets individually page by page i would like to define by default that the parent page will inherit the widget to its child pages if they don't have any (inherit as sitetree).

thanks

Avatar
Nivanka

Community Member, 395 Posts

25 January 2009 at 1:56am

You can edit the Page.php, and add some methods then it will install the widgets on your pages.

Check how the blog module has done,

let me know I will post something if you need.

Avatar
tzeller

Community Member, 26 Posts

25 January 2009 at 2:24am

Edited: 25/01/2009 2:31am

thanks nivanka for you quick response.

do i get this right. you mean above function from the "BlogHolder.php", right?
-----
function requireDefaultRecords() {
      parent::requireDefaultRecords();
      
      if(!DataObject::get_one('BlogHolder')) {
         $blogholder = new BlogHolder();
         $blogholder->Title = "Blog";
         $blogholder->URLSegment = "blog";
         $blogholder->Status = "Published";
         
         $widgetarea = new WidgetArea();
         $widgetarea->write();
         
         $blogholder->SideBarID = $widgetarea->ID;
         $blogholder->write();
         $blogholder->publish("Stage", "Live");
----

change it in ?

function requireDefaultRecords() {
      parent::requireDefaultRecords();
      
      if(!DataObject::get_one('Page')) {
         $blogholder = new BlogHolder();
         $blogholder->Title = "Blog";
         $blogholder->URLSegment = "blog";
         $blogholder->Status = "Published";

         
         $widgetarea = new WidgetArea();
         $widgetarea->write();
         
         $page/color]->SideBarID = $widgetarea->ID;
         $page/color]->write();
         $page/color]->publish("Stage", "Live");

i have successfully added widget to all my pages and can place individually the widgets per page. now i want that my parent page (ie "about us") will inherit its widgets to its children pages (ie "company profile" in the site tree of about us).
thanks

Avatar
Nivanka

Community Member, 395 Posts

25 January 2009 at 7:10am

Yes thats what I meant.

Avatar
tzeller

Community Member, 26 Posts

2 February 2009 at 4:48am

i don't know what i am doing wrong.

this is the code i added to my page.php:

   function requireDefaultRecords() {
      parent::requireDefaultRecords();
      
      if(!DataObject::get_one('Page')) {
         $widgetarea = new WidgetArea();
         $widgetarea->write();
         
         $page->SideBarID = $widgetarea->ID;
         $page->ParentID = $page->ID;
         $page->write();
         $page->publish("Stage", "Live");
         
         $widgetarea->write();
      }
   
   }

there is no change - i still can add my widgets page by page... but they are not inheriting from parent-pages to children-pages.

hopefully somebody can help my.

thanks

Avatar
dio5

Community Member, 501 Posts

2 February 2009 at 6:14am

You could also make a method for displaying on the templates only, in which you loop through the parents checking for widgets. There would be no real widget saved in the db for that page, but it would be enough for displaying them.

Go to Top