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
- 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(",")
- 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