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') ?>