Tags are not spliting

Hey.

I have a filter by tags function, but the tags won’t split(","). That causes an array with just one item (all the tags after each other separated by ","). Obviously it should be each tag = one item itself.

I did this operation before on the same site – there it works. I copied an adjusted very carefully and checked everything three times.
I don’t know if I am missing some logical mistake, using a similar function again, so I will show you both – first one works, sec. not

  1. Filtering of the images of the page by tags added in the panel to the page. This works

controller:

$files = $page->files();
$tags = $files->pluck('tags', ',', true);
if($tag =urldecode(param('work'))) {
   $files = $files->filterBy('tags', $tag, ',');}

template:

  <?php foreach($tags as $tag): ?>
      <a <?php if( param('work') === $tag ) { echo('class="active_tag tag big_typo"'); } ?> class="tag big_typo pointer" href="<?= url($page, ['params' => ['work' => urlencode($tag)]]) ?>">
        <?= html($tag)?>
      </a> </br>
  <?php endforeach ?>

text file:

----

Tags: portraits, animals, fragments

----

blueprint page:

columns:
- width: 1/2
   sections:
     info:
        type: fields
        fields:
          tags:
             type: tags
             separator: ","

blueprint files:

      tags:
        label: Tags
        type: checkboxes
        options: query
        query: file.parent.tags.split(",")

  1. Filtering entries in a list (with the [toStructure](https://getkirby.com/docs/reference/panel/fields/structure#how-to-use-in-templates-snippets) medthod) tags added in the panel to the page. This doesn’t work

controller:

$entry_tags = $page->tags();
$strc_tags = $entry_tags->pluck('tags', ',', true);
if($tag =urldecode(param('tag'))) {
  $entry_tags = $entry_tags->filterBy('tags', $tag, ',');}

template:

<?php foreach($strc_tags as $tag): ?>
      <a <?php if( param('tag') === $tag ) { echo('class="active_tag tag big_typo"'); } ?> class="tag big_typo pointer" href="<?= url($page, ['params' => ['tag' => urlencode($tag)]]) ?>">
        <?= html($tag)?>
      </a> </br>
<?php endforeach ?>

Text file:

----

Tags: all, exhibition, life

----

blueprint page:

columns:
- width: 2/3
sections:
  info:
    type: fields
    fields:
      tags:
        type: tags
        separator: ","
      about:
        label: Into
        type: textarea
        maxlength: 300
- width: 1
sections:
  Vita:
    type: fields
    fields:
      Vita_points:
        label: Vita
        type: structure
        fields:
          year:
            type: text
          entry:
            type: text
          tags:
            label: Tags
            type: checkboxes
            options: query
            query: page.tags.split(",")

I tried: renaming the variables, changing the split signs, changing the order of the “if” in the controller.
No effect alt all.

Unless there is a stupid misspell or syntax mistake i don’t understand the different behavior. Maybe anyone sees a something in the code.

Kind regards

You cannot pluck anything from a field, pluck() is a collection method, not a field method. You probably mean to pluck the tags from the structure field called vita_points?

But then ´$entry_tags` would have to be defined like this:

$entry_tags = $page->vita_points()->toStructure();

Or if you want to get the tags from the tags field, then you have to use the split() method as in your first example.

$tags = $page->tags()->split(',');

Ah, That was the hint!
I was looking for the tags.

  $entry_tags = $page->vita_points()->tags()->toStructure();
  $strc_tags = $entry_tags->pluck('tags', ',', true);
  if($tag =urldecode(param('tag'))) {
     $entry_tags = $entry_tags->filterBy('tags', $tag, ',');}

Now it works! :smiling_face_with_three_hearts:

That syntax is not correct though, as I wrote above, should be

$page->vita_points()->toStructure();

Ah. It seems to be no difference in the outcome.