I’m building a multi-language portfolio page where we want to publish teasers for projects that are work in progress.
So I included
wip:
width: 1/3
label: Work in Progress?
translate: false
type: toggle
text:
-
en: finished
de: fertig
-
en: "Work in Progress"
de: "in Arbeit"
This works fine in the panel. But I want to show the wip-label on the teaser. Is there a way to get the translated wip-toggle text from the blueprint?
Thanks in advance!
Edit: Building the template, I made it as far as getting an “Array” output from:
<?php foreach ($pages->listed() as $project): ?>
<li class="item">
<a class="wrapper" <?php if($project->wip()->bool() === false): ?>href="<?= $project->url() ?>"<?php endif ?>>
<img src="<?= $project->teaser()->toFiles() ?>" />
<h2><?= $project->title() ?></h2>
<?php if($project->wip()->bool()): ?>
<small><?= $project->blueprint()->field('wip') ?></small>
<?php endif ?>
</a>
</li>
<?php endforeach ?>
Yes, via the $page->blueprint()
method.
You can find an introduction how to use this in our cookbook:
Pageblueprint object: $pageblueprint | Kirby
Oh, I just edited. I got the reference, but the Output I receive on the HTML is only “Array” from
<?php foreach ($pages->listed() as $project): ?>
<li class="item">
<a class="wrapper" <?php if($project->wip()->bool() === false): ?>href="<?= $project->url() ?>"<?php endif ?>>
<img src="<?= $project->teaser()->toFiles() ?>" />
<h2><?= $project->title() ?></h2>
<?php if($project->wip()->bool()): ?>
<small><?= $project->blueprint()->field('wip') ?></small>
<?php endif ?>
</a>
</li>
<?php endforeach ?>
Because
$project->blueprint()->field('wip')
returns an array. Do a
dump($project->blueprint()->field('wip'));
to see what this array contains, from there you see how you can access what you need.
This is what your array will contain:
Array
(
[width] => 1/3
[label] => Work in Progress?
[translate] =>
[type] => toggle
[text] => Array
(
[0] => Array
(
[en] => finished
[de] => fertig
)
[1] => Array
(
[en] => Work in Progress
[de] => in Arbeit
)
)
[name] => wip
)
Thanks, @texnixe.
If anyone in the future is looking for the final code snippet, it’s
<?= t($project->blueprint()->field('wip')['text']['1']); ?>