List tags for a page

Hi!

I am creating a page that lists projects i.e. child pages of the “projects” page. Next to each project name/URL, I would like to list its tag. Each tag should be listed individually, so I can wrap it in an HTML element. I am currently trying this with the pluck() method, but I just can’t get it to list the tags separately.

I followed Filtering with tags | Kirby CMS and tried to adapt it to a single page, but can’t get it to work.

I’ve highlighted what I am trying to do below with comments. What am I doing wrong?

Thanks in advance!

<?php snippet('header') ?>
<?php snippet('nav') ?>
<h1><?= $page->title() ?></h1>
<p><?= $page->text()->kirbytext() ?></p>

<table border="2">
<tr>
<th>Date</th>
<th>Project</th>
</tr>
<?php 

$projects = page('projects')->children()->listed()->sortBy('start', 'desc');

foreach ($projects as $project):


# get the individual tags for the current $project - does not work / comes up empty
$tags = $project->pluck('tags', ',', true);


?>

<tr>
<td>

<?php

	if ($project->end()->isNotEmpty()): 
		echo $project->start()->toDate('Y-m'); 
		echo " to " . $project->end();
	else:
		echo "Since " . $project->start();
	endif;
	?>

</td>
<td>
	<a href="<?= $project->url() ?>">
	<?= $project->title() ?>
	</a>

      # here I'd like to list each tag separately, wrapped in a span element. comes up empty.
	<?php
	foreach ($tags as $tag):
	?>
	<span><?=  $tag ?></span>
	<?php endforeach ?>

</td>
</tr>
<?php endforeach ?>
</table>

<?php snippet('prevnext') ?>
<?php snippet('footer') ?>

This should be

$tags = $project->tags()->split();

pluck() is a collection method, not a field method.

Thanks once again for your swift and on point answer! That solved my problem :blush:

Here are the steps involved, I hope this is helpful for others.

  1. Get all the project pages, sorted by (start) date and loop through them with foreach
$projects = page('projects')->children()->listed()->sortBy('start', 'desc');
foreach ($projects as $project):

As per Sorting collections | Kirby CMS.

  1. Get the individual tags for the current page

$tags = $project->tags()->split();

  1. Loop through the tags and wrap them in spans
 foreach ($tags as $tag):
 <span><?=  $tag ?></span>
 <?php endforeach ?>

Steps 2 and 3 are documented in $field->split() | Kirby CMS.