Jump to content

repeater block/page title


elvina
 Share

Recommended Posts

Hi,

I have a repeater on a page. It is a committe with different sections, so I have each section as a repeating block containing another repeater with the members.

eg.

  1. Block: title="Presidency", contains Ms J. Smith - President, Mr J. Brown - Treasurer etc 
  2. Block: title="Executive Committee" contains other members.

This all works fine, but when I edit in the front end, the Block editor comes up with my repeater field but says "editing block 21245454354" and opens saying "editing page 21245454354".

I can see these are the page titles in the admin, but is there a way to have these pages named as the title of that block? 

thanks

Link to comment
Share on other sites

OK, I had to fiddle with getting the right hooks. As the page is made before the title field is entered in the repeater.

So this renames the repeater page with the field title and the year field of the original page holding the repeater.

$wire->addHookBefore('Pages::save', function(HookEvent $event) {
    $page = $event->arguments(0);
       
    if($page->template->name == 'repeater_committee_section') {
        $title = $page->field_title;
        $year=date('Y', $page->getForpage()->starts);
        if (!empty($title)) {
            $page->name = $page->field_title . "-" . $year;
        }
    }
});

 

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...