Jump to content

Get property of parent repeater item


Zeka
 Share

Recommended Posts

Hi!

I have a page with a repeater field with a nested repeater field. On another page, I have page reference field (Asm)  where items from nested repeater could be selected. In settings for this field I set "Custom format" for field label and "{title} | ({parent.title}) as a 'page custom label format' then I get 'title | (1518957362-4249-1)' as labels where 1518957362-4249-1 is the actual parent of this repeater item in page tree. Am I right in saying that there is no way to get title or another property of parent item? Also, as I can see, there is 'getPageLabel' method, but it's not hookable. Any thoughts? 

And one more question, is there getForPage() in dot notation? (e.g page.getforpage.title )

Thanks. 

Link to comment
Share on other sites

You can set more advanced labels in a Page Reference field by using a hook. Not sure if there's a better way but here's how I do it.

In your Page Reference field settings, choose "Custom format" for the "Label field" setting, and in the "Custom page label format" enter anything you want so long as it is unique to that field, e.g.

pwrocks

Then in /site/ready.php

$wire->addHookAfter('Page::getMarkup', function(HookEvent $event) {
    $page = $event->object; // Each page that appears in the Page Reference field
    $key = $event->arguments(0);
    if($key !== 'pwrocks') return; // the label format specified for the Page Reference field
    // Now build whatever string you want to show using $page, $page->getForPage(), etc
    $string = 'Your string here';
    $event->return = $string;
});

 

Edited by Robin S
Edit: slightly more efficient if you don't use curly brackets in your dummy label format.
  • Like 2
  • Thanks 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...