i am wondering if there is any possiblity that i can automatically inherit a widget from the parent to all children?
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.
- Page 11(current)
- 2
- Next 10 entries
what do you mean? do you need to add a widget to all the pages or what?
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
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.
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
Yes thats what I meant.
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
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.
- Page 11(current)
- 2
- Next 10 entries