Jump to content

page-field selector multiple parents | create new page


ngrmm
 Share

Recommended Posts

i'm using a page-field with the inputfield-chosen-select-multiple as a tag-system
– there are two different templates (template_A & template_B) which can be chosen
– and both have different parents (parent_of_A's & parent_of_B's)
– new pages (tags) generated from this field should be children of parent_of_A's and have template_A

so i've chosen parent_of_A's as the parent and template_A as template. and selected template_B as extra template. this is must because that how the system know where to put the new pages.
but this does not work when i try to add other templates as extra-templates or with the selector string method.
error says: not the right template

only using selector-string-method works for choosing, but no new pages can be generated

Link to comment
Share on other sites

I'm not sure I understand your setup.

e.g. why don't you use a separate parent and template for tags?

Do you have any settings in your parent templates that say "only pages with template x are allowed as children"?

21 minutes ago, ngrmm said:

and selected template_B as extra template

"extra template" = additional template?

I guess the system is confused because you allow two templates for selecting, and is not sure where to create new pages. afaik there's no additional settings where you could define that. You'd probably have to create a hook for that.

Link to comment
Share on other sites

1 minute ago, dragan said:

e.g. why don't you use a separate parent and template for tags?

i'm trying to reduce redundancy and creating a structure which can be used later (relation-links)
some existing should be also used as tags beside the new ones.

 

1 minute ago, dragan said:

Do you have any settings in your parent templates that say "only pages with template x are allowed as children"?

yes

1 minute ago, dragan said:

"extra template" = additional template?

yes

 

1 minute ago, dragan said:

I guess the system is confused because you allow two templates for selecting, and is not sure where to create new pages. afaik there's no additional settings where you could define that. You'd probably have to create a hook for that.

ok, i though PW would use the first settings (parent/template) for creating the new pages, and additional setting and selector for additional options

any tutorials/how-to for backend-hooks?

 

Link to comment
Share on other sites

@ngrmm, you can do this by not defining a parent for selectable pages in the field settings (just define a template) and add the following in /site/ready.php:

$wire->addHookBefore('InputfieldPage::renderAddable', null, 'setAddParent');
$wire->addHookBefore('InputfieldPage::processInputAddPages', null, 'setAddParent');
function setAddParent(HookEvent $event) {
	$inputfield = $event->object;
	// Only for this one Page Reference field
	if($inputfield->hasField != 'tags') return;
	// Only for ProcessPageEdit
	if($event->wire('process') != 'ProcessPageEdit') return;
	// Set the ID of the parent page that new pages should be added under
	$inputfield->parent_id = 1234;
}

 

  • Like 2
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...