Jump to content

In "List of fields to display in admin Page List" (template settings) how to display field from 1st repeater field item?


hellomoto
 Share

Recommended Posts

For a repeater field called datetimes, when I just put "{datetimes.date} {datetimes.time}" the output for one with multiple entries is (paraphrased):

1stdate, 2nddate 1sttime, 2ndtime

Is there a way of just specifying the 1st item's values in the repeater here?

Link to comment
Share on other sites

It's possible with a hook.

In the "List of fields to display in the admin Page List" setting for the template, enter a string that identifies where the value from the first repeater will go, e.g. first_repeater_datetime. Don't put the normal { } delimiters around this string.

Then add a hook like this in /site/ready.php:

$wire->addHookAfter('ProcessPageListRender::getPageLabel', function(HookEvent $event) {
	$page = $event->arguments(0);
	$out = $event->return;
	if($page->template == 'your_template') {
		$datetime = '';
		if($page->datetimes->count) {
			$first_item = $page->datetimes->first();
			$datetime = $first_item->date . ' ' . $first_item->time;
		}
		$event->return = str_replace('first_repeater_datetime', $datetime, $out);
	}
});

 

  • Like 5
  • Thanks 1
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...