retak
September 18, 2020, 3:00pm
1
Hello together,
i’ve to following setup:
in the project blueprint i have checkboxes for visibility with these options
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):?>
retak
September 18, 2020, 4:17pm
3
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.
texnixe
September 18, 2020, 4:22pm
4
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?
retak
September 18, 2020, 4:31pm
5
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 ?>
texnixe
September 18, 2020, 4:43pm
6
retak:
'$key'
This should be without quotes
retak
September 24, 2020, 10:22am
7
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