Need advice with filtering

Firstly I am new to Kirby.
I have set up a site with 20 + pages.
I also have a highlight page, on this highlight page I wish to show just the files (these are images, quotes etc.) that are marked as a highlight.
This means I need to create a filter system my first idea was to use a select box but after checking the docs maybe a tag filter system is better. (Any advice?)
I need the filtered items to be ordered by date on the highlight page.
I also want that the highlighted items only show once, on the highlights page and NOT on the ‘normal’ page.
Any help, advice, tips or pointers towards the correct way of achieving this would be wonderful, Thank you!

Since this is the case, wouldn’t it be simpler to have the highlights simply be the children (or files) of the highlights page? No filtering needed then.

How are these items marked as highlights? I mean, for images this can be metadata, but what are these quotes, subpages? What other types of items?

Here is the link: http://www.derkleineherrmann.de
The ‘highlights’ would come in the ‘Heutzutage’ Section (first section in pink)
The highlights would in time be taken from each of the other sections, at present just a few of the other sections have a highlight.
I wanted to keep the highlight section dynamic meaning the artist only has to add the item once and add either a tag or tick a select box to turn the highlight function on and off.

So these will actually all be pages, right?

@pixelijn That was the plan.

Ok, I think @rasteiner suggestion makes sense if the highlights don’t change. Otherwise, I add a toggle or so and filter by this toggle.

So on the highlights page you would filter the pages by this toggle where true, in the other parent by false.

@texnixe thank you, that is my thought pattern but as being new to Kirby I am still exploring how to put such a toggle effect into action. Do you have any Kirby links for me?

aha found it: Toggle | Kirby CMS

Could you help me here?
I would like to filter all pages and sort by date field.
Not sure how to start…

Here’s how to sort by date: Sorting | Kirby CMS
And here’s how to filter: Filtering compendium | Kirby CMS

Filtering by a toggle would look like $pages->filterBy('highlight', true);

Thank you @rasteiner
on the pages where I am adding the filterby toggle as false all working as expected for the highlight page itself I am stumbling without getting anything showing…

This is what I am using for the other pages:

<?php
			// using the `toStructure()` method, we create a structure collection
			$items = $page->lyrik()->toStructure()->filterBy('toggle', false);
			// we can then loop through the entries and render the individual fields
			foreach ($items as $item): ?>
			<figure class="text-center odd-five">
                <blockquote class="blockquote">
	                <h3 class="pb-3"><?= $item->titel()->html() ?></h3>
                    <?= $item->text()->kt() ?>
                </blockquote>
                <figcaption class="blockquote-footer pt-3">
                    <cite title="Source Title">Name</cite>
                </figcaption>
            </figure>
            <?php endforeach ?>

If I change the first line to:

$items = $pages->toStructure()->filterBy('toggle', true);

I am getting an ‘Call to a member function filterBy() on null’ error.

What I am having a problem with is understanding the correct way to call all the pages is ‘$pages’ correct?

$pages is just a variable name I made up. The idea being that you somehow would have a collection of pages that you want to filter.

Presumably your real code might look something like:

<?php 
$allNotes = page('notes') // change 'notes' to your case
    ->children()
    ->listed()
    ->sortBy(fn($page) => $page->date()->toDate(), 'desc');

$highlights = $allNotes->filterBy('highlight', true);

/*
// you can also write it all in one call:
$highlights = page('notes') // change 'notes' to your case
    ->children()
    ->listed()
    ->sortBy(fn($page) => $page->date()->toDate(), 'desc');
    ->filterBy('highlight', true);
*/

?>

<?php foreach($highlights as $item): ?>
  <figure class="text-center odd-five">
      <blockquote class="blockquote">
          <h3 class="pb-3"><?= $item->titel()->html() ?></h3>
          <?= $item->text()->kt() ?>
      </blockquote>
      <figcaption class="blockquote-footer pt-3">
          <cite title="Source Title">Name</cite>
      </figcaption>
  </figure>
<?php endforeach; ?>

The point of separating them into $allNotes and $highlights is that you could, if you want to, then extract $allNotes into a “Collection” at some point. Like:

site/collections/notes.php

<?php

return function () {
    return page('notes')
        ->children()
        ->listed()
        ->sortBy(fn($page) => $page->date()->toDate(), 'desc');
};

Then in your highlights page you could write it just like this:

<?php foreach(collection('notes')->filterBy('toggle', true) as $item): ?>
  <figure class="text-center odd-five">
      ...
  </figure>
<?php endforeach; ?>

and in your normal page like this:

<?php foreach(collection('notes')->filterBy('toggle', false) as $item): ?>
  <figure class="text-center odd-five">
      ...
  </figure>
<?php endforeach; ?>

toStructure() is something you need when you use a structure field.

I have been using a structure field on the other pages, which may have been a bad decision as I am still learning Kirby. I have moved over to kirby from Perch (which has basically died). My thinking was that the structure field would be used as a replacement for the Perch repeaters but as I say maybe a bad decision…

structure fields are fine :slight_smile:

The main differences are that:

  1. pages get their own folder (that could contain files with the same name as other pages)
  2. pages have URLs
  3. structure fields are all saved into the same text file.

If you don’t want single items to be accessible by their own URL, and are mostly going to always show all items together, structure fields are probably the better choice.
If you want to have a “detail page” (for example) for an item, having separate pages is probably better.

So, it really depends :slight_smile:

I just thought that you had pages because of this:

Thanks @rasteiner unfortunatley not working.

On this page: Thomas Bäder / Aphorismen
I am using the following blueprint:

title: Aphorismen

fields:
  aphorismen:
    label: Aphorismen
    type: structure
    columns:
      quote:
        width: 7/10
      toggle:
        width: 1/10
      datum:
        width: 2/10
    fields:
      quote:
        label: zitaet
        type: textarea
      toggle:
        width: 1/4
        label: Heutzutage?
        type: toggle
        text: 
          - "Nein"
          - "Ja"
      datum:
        label: Heutzutage datum
        type: date
        display: D.M.YYYY
        width: 1/3

accompanied with following template:

 <?php
	// using the `toStructure()` method, we create a structure collection
	$items = $page->aphorismen()->toStructure()->filterBy('toggle', false);
	// we can then loop through the entries and render the individual fields
	foreach ($items as $item): ?>
	<div class="blockquote-container odd-one">
        <blockquote class="bq-style">
            <p><?= $item->quote()->html() ?></p>
            <footer>Thomas Bäder</footer>
        </blockquote>
    </div>
	<?php endforeach ?>

This setup I have repeated for the other pages.
On the ‘highlights’ page I wish to use true instead of false on the toggle (i have named the toggle toggle maybe a bad decision)

AND

call the other pages too!
That is why I am getting confused with the $pages variable, I thought this would call all the pages that are on the site (ca. 17) and then filter them with the toggle.

It’s possible that items that weren’t saved after you added the toggle to the blueprint do not explicitly contain the “toggle: false” data.
Could you share the contents of the text file in content/aphorismen (there might be a number before “aphorismen”)?

Otherwise you could try with something like:

$items = $page->aphorismen()->toStructure()->filterBy('toggle', '!=', true);

yes there is a number “content/2_aphorismen” the text file ther within has just the title given.

Then

$items = $page->aphorismen()->toStructure()->filterBy('toggle', '!=', true);

should work.
The reason being that the field is not strictly false, but null (i.e. “an empty field”).

Now I am getting the page but no filtered content.