How to fetch options from blueprint for filtering

Hello together,

i’ve to following setup:

  • projects
    • project1
    • project2
    • project3…

in the project blueprint i have checkboxes for visibility with these options

  • all
  • opt1
  • opt2
  • opt3

Now i want the following:

on the projects-page list all blueprint-options to filter my projects.

I’m struggling with fetching the options from the project-blueprint on the projects-page.
This is the checkboxsetup in th project-blueprint

          type: fields
          fields:
            visibility:
              label:
                de: Filter
                en: Filter
              type: checkboxes
              default: all

              options:
               all:
                de: "Alle Projekte"
                en: "All projects"
                fr: "Tout les projects"
               opt1:
                de: "mobarch"
               opt2:
                de: "ausarch"
               opt3:
                de: "konbau"

The filter works like that:

  foreach ($site->search('opt1',['visibility']) as $project):?>

You can do that via the $page->blueprint() method, more info: https://getkirby.com/docs/cookbook/templating/blueprints-in-frontend

I tried it in so many ways.
I can’t figure out, how to adress the blueprint:

$page->grandchildren()->first()->blueprint()->field('visibility')

    Array
(
    [label] => Array
        (
            [de] => Filter
            [en] => Filter
        )

    [type] => checkboxes
    [default] => all
    [options] => Array
        (
            [all] => Array
                (
                    [de] => Alle Projekte
                    [en] => All projects
                    [fr] => Tout les projects
                )

            [opt1] => Array
                (
                    [de] => mobarch
                )

            [opt2] => Array
                (
                    [de] => ausarch
                )

            [opt3] => Array
                (
                    [de] => konbau
                )

        )

    [name] => visibility
    [width] => 1/1
)

That’s the leas i got.

But your are almost there, the rest is just getting the options from the array:

$field = $page->grandchildren()->first()->blueprint()->field('visibility');

// The options array
$options = $field['options'] ;
// The keys only
$options = array_keys( $field['options'] );

What exactly do you need?

Thanks so much!

At the end i need this:

  <?php
  <ul>
   foreach ($keys as $key):?>
    <li>
    <a href="$site->search('$key',['visibility'])">

     $key

   </a>
  </li>
<?php endforeach ?>

and:

  <?php
  foreach ($site->search('opt1',['visibility']) as $project):?>
  <picture>
  <a href="<?= $project->url() ?>">
    <?php if ($image = $project->hero()->toFile()):?>
      <img
      srcset="<?= $image->srcset('gallerie') ?>"
      src="<?= $image->resize('300')->url() ?>"
      sizes="(max-width: 1400px) 350px, 700px"
      alt="<?= $image->caption()->isNotEmpty()?  $image->caption()->html() : $project->title()->html(). " " . $image->filename() ?>">
    <?php elseif ($image = $project->images()->first()):?>
      <img
      srcset="<?= $image->srcset('gallerie') ?>"
      src="<?= $image->resize('300')->url() ?>"
      sizes="(max-width: 1400px) 350px, 700px"
      alt="<?= $image->caption()->isNotEmpty()?  $image->caption()->html() : $project->title()->html(). " " . $image->filename() ?>">
    <?php endif ?>
  </a>
  </picture>

<?php endforeach ?>

This should be without quotes

Thank you for the help. It’s working now.

I also found the find blueprint, but i can’t get it to work.

Is there an easier way to retrieve the blueprint?

Could you post what you tried?

But I don’t think the result would be any different