Jump to content

Create a field and enter settings on parent page and child page can select those options in the back-end admin panel?


OpenBayou
 Share

Recommended Posts

I have a page called 'Podcasts ADs' with a field called 'podcast_show' that a repeater with a text field and an image uploader.

Is there a way for the child pages in 'Podcasts ADs' to select data from those fields in the parent in the admin panel in the back-end?

Example: If I enter in a show name called 'Show' in the text, I can select 'Show' in the child pages.

Thanks.

 

Link to comment
Share on other sites

Yep, you want a Page Reference field on the child pages.

For "Label field" select the text field used in your repeater.

Use the "Custom PHP option" for "Selectable pages" by creating the following hook in /site/ready.php:

$wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) {
    if($event->object->name == 'my_page_reference_field') {
        $page = $event->arguments('page');
        $event->return = $page->parent->podcast_show;
    }
});

 

  • Like 3
Link to comment
Share on other sites

I got it to show up on the back-end editor but it doesn't show the title.

Untitled-1.jpg

The field above is called 'podcast_shows_child' and this is on a child page.

 

Untitled-2.jpg

The above field is on the parent page that's a repeater called 'podcast show' and the two fields are an image and a text field. The image field is called 'podcast_show_image' and the text field is called 'podcast_show_name'

Thanks for the help. I tried doing it myself but I've been working on this site for four days and I'm not thinking properly.

P.S. This is the tree

Untitled-3.jpg

Link to comment
Share on other sites

1 hour ago, kongondo said:

Show us the code in your /site/ready,php as per Robin's suggestion...Maybe you have a typo there.

Have no idea what ready.php is. All I've done was change the field to page, did 'custom PHP code to find selectable pages'.

<?php $wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) {
    if($event->object->name == 'podcast_shows_child') {
        $page = $event->arguments('page');
        $event->return = $page->children->podcast_show;
    }
});?>

 

Link to comment
Share on other sites

OK. It seems you are using an older version of ProcessWire, pre-dating the change in using custom code in page fields (can't remember in what version of ProcessWire 3.x this was introduced). Anyway, then the below is the FORMAT of the code that you need to enter in the custom code textarea. Adapt it to your needs; e.g. a suggestion was made for $page->parent->podcast_show but I see you are using children instead. Also note that I don't know what podcast_show is, so don't know if that code will return anything. This is just a pointer

return $page->children->podcast_show;

 

Link to comment
Share on other sites

Solved it. Went the simpler route and created a hidden page and used the field to select those pages. Thanks for the help.

One problem: the page is called 'podcast' and a field called 'podcast_shows' that lists pages from the 'podcast' page. How do I show the selected title from the field? '<?php echo $page->podcast_shows?>' shows the page ID. '<?php echo $page->podcast_shows->title?>' shows nothing.

 

Link to comment
Share on other sites

1 hour ago, OpenBayou said:

...One problem: the page is called 'podcast' and a field called 'podcast_shows' that lists pages from the 'podcast' page. How do I show the selected title from the field? '<?php echo $page->podcast_shows?>' shows the page ID. '<?php echo $page->podcast_shows->title?>' shows nothing.

Did you see this post in your other thread :)?

If podcast_shows is a multi-page field, it doesn't matter whether you have one or more pages selected in it; it will return a PageArray.

Edited by kongondo
  • 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...