Jump to content

Custom page list label


Krlos
 Share

Recommended Posts

Hi, I need to place an icon or label in some pages in my tree.

I found that page list label allows to change the format for the label like this:

{categories.title} {title}

How can turn that into this:

labels.jpg.6ad3431c3130560ee31bb78e4003358f.jpg

That label is page reference.

Thanks in advance.

Link to comment
Share on other sites

Assumes "categories" is a multiple Page Reference field and that you have a hex colour defined on each category page:

$wire->addHookAfter('ProcessPageListRender::getPageLabel', function(HookEvent $event) {
	$page = $event->arguments(0);
	if($page->template == 'accommodation') {
		$out = '';
		foreach($page->categories as $category) {
			$out .= "<span class='uk-label' style='background-color:$category->hex_colour'>$category->title</span> ";
		}
		$out .= $page->title;
		$event->return = $out;
	}
});

2022-01-11_100531.png.249adc128536350e0236656a6c6e3e9d.png

  • Like 4
  • 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...