Hello,
Can a page type be configured to automatically create a child page when it is created?
Example: user creates a SpecialPage; a ChildSpecialPage automatically appears underneath the new SpecialPage.
Thank you,
Ben
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
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.
Hello,
Can a page type be configured to automatically create a child page when it is created?
Example: user creates a SpecialPage; a ChildSpecialPage automatically appears underneath the new SpecialPage.
Thank you,
Ben
This is possible! http://silverstripe.org/customising-the-cms/show/256077#post256077 clued me in.
In the page under which the child pages should automatically be created:
public function onAfterWrite() {
$cp = new ChildPage();
$cp->ParentID = $this->ID;
$cp->Title = "Test Page";
...
$cp->write();
return parent::onAfterWrite();
}
hmmm could you show complete code ?
in ProgramHolder i paste yours but it doesn't work
class ProgramHolder extends SiteTree {
static $db = array(
);
static $has_one = array(
);
static $allowed_children = array('ProgramPage');
}
class ProgramHolder_Controller extends ContentController {
public function onAfterWrite() {
$cp = new ProgramPage();
$cp->ParentID = $this->ID;
$cp->Title = "Test Page";
$cp->write();
return parent::onAfterWrite();
}
}
Hi Snaip,
Your code looks similar to mine, except for the location of onAfterWrite(). It needs to be in the ProgramHolder class, not the controller class. It's after ProgramHolder is written that the children should be created.
Ben
nothing :(
sometimes i hate SS :[
you are using 2.3 right? There was no onAfterWrite() in previous stable versions.
yeeeee it works in 2.3 :)
thx xD
it works but ... it's creating me 4 copies of the same page ? !!
when i create ProgramHolder it adds me one ProgramPage, ok
next log out, log in, and im geting another 3 copies of the new ProgramPage !!
why ? !