lpa Posted February 2 Posted February 2 I have defined a Page Reference field in my template. I want to be able to create new pages through that field. I am using AdminPageFieldEditLinks-module. My problem is that I would like to define the new pages to be created as childs to the current page. I don't know how to define Selectable Pages to be the children of the current page. If I leave Selectable pages:Parent empty, I get the error: ProcessWire: ProcessPageAdd: No parent templates defined for <template> Any idea if this is possible and how to define the target of the new pages to be children of the current page?
Gideon So Posted February 3 Posted February 3 Hi @lpa 1. Enable "Allow new pages to be created from field?" in the input tab of the field. 2. Specify the parent and template of the future newly create pages 3. Done. Gideon 1
lpa Posted February 3 Author Posted February 3 Thank you for your answer. Off course I know that it should work like that. Maybe my question was not clear enough. I asked, how could I define the new pages to be created as childs of the current page as I can't select the "current page" dynamically. I tried to define it like "parent=[page]", but that did not work.
Robin S Posted February 4 Posted February 4 In your field settings define "Template" for selectable pages but not "Parent". Check the "Enable link to create new pages?" checkbox that is added by the AdminPageFieldEditLinks module, but don't select anything in the "Parent for new pages created" field. Add the following hook to your /site/ready.php to define the parent dynamically. $wire->addHookBefore('InputfieldPage::render', function(HookEvent $event) { /** @var InputfieldPage $inputfield */ $inputfield = $event->object; $page = $inputfield->hasPage; $field = $inputfield->hasField; if($page && $field && $field->name === 'your_field_name') { $inputfield->parent_id = $page->id; } });
lpa Posted February 4 Author Posted February 4 Great! That was just what I needed. I think there is something missing or a bug in AdminPageFieldEditLinks as it says it should give me the opportunity to select the path where save the new page if no Parent is given. Now it gives me an error. And maybe the Select Parent should somehow support the dynamic parent to be the current page.
JosephineNeill Posted February 14 Posted February 14 (edited) Thank you so much for the help. Edited March 12 by JosephineNeill
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now