Tags configuration

Hi everyone !
I post my first question on this forum because i’m a little lost with tags configuration.

I’m actually working on a portfolio website for Architectes and they need to add tags on there projects albums. After that, i have to create a list with all this tags to filter projects on a “Projects” page.
I have created tags field in my “Album.yml” blueprint but i don’t know how to activate tags in controllers.

Here is my Album.yml

title: Album
icon: đź–Ľ

status:
  draft: true
  listed: true

tabs:
  images:
    label: Images
    icon: file-image
    columns:
      left:
        width: 2/3
        sections:
          images:
            type: files
            layout: cards
            template: image
            info: "{{ file.dimensions }}"
            image:
              ratio: 16/9
              cover: false
            min: 0
            size: tiny
      right:
        width: 1/3
        sections:
        fields:
          toggle:
            label: Apparaître sur la home ?
            type: toggle
            text:
              - 'non'
              - 'oui'

  content:
    label: Contenu
    icon: text
    columns:
      left:
        width: 2/3
        sections:
        fields:
           st:
            label: Sous-titre
            type: text
          description:
            type: textarea
          ouvrage:
            label: Maître d'ouvrage
            type: textarea
          groupement:
            label: Groupement
            type: textarea
      right:
        width: 1/3
        sections:
        fields:
          lieu:
            label: Lieu
            type: text
          year:
            label: Année
            type: text
          superficie:
            label: Superficie
            type: text
          statut:
            label: Statut
            type: text
          tags:
            label: tags
            type: tags
            option: query

Here is my projets controllers

<?php

return function ($page, $kirby, $site) {

	$tags = $page->children()->visible()->pluck('tags', ',', true);


return [

    'tags' => $tags
];

};

This is correct, apart from the deprecated visible() method, which should be listed().

In your example $tags will give you an array of all tags from all children.

Your blueprint setup with options: query without a query is not quite right though.

What exactly doesn’t work as expected?

Hello Pixelijn,
Thank you very much for your answer. Now it’s working, i think the problem was i forgot the “listed()”.
Now it’s fine, i can display all my children’s tags.

But now, i got another problem, here’s my projects page :

On the left we have tags, on the rights we have albums.
When i click on a Tag, i’d like to display only albums who have this Tag. How can i do this ?

Here is my code :

<?php snippet('header') ?>

<main>

<p class='random-color' id='title-themes'>Thèmes</p>
<p class='random-color' id='title-list'>Projets</p>


<ul id="themes">
    <?php foreach($tags as $tag): ?>
      <li class='tag'>
        <a href="<?php echo url($page->url() . '/' . url::paramsToString(['tag' => $tag])) ?>">
          <?php echo html($tag) ?>
        </a>
      </li>
      <?php endforeach ?>
</ul>

<ul id="list">
  <?php foreach (page('projets')->children()->listed() as $album): ?>
    <li class='projet'>
      <a href='<?= $album->url() ?>'>
        <p><?= $album->title() ?> <sup><?= $album->year() ?></sup></p>
      </a>
    </li>
    <?php endforeach ?>
</ul>

</main>
<?php snippet('footer') ?>

You would have to filter the projects by tag when the parameter is set, you can find a recipe here:

1 Like