In the frontend, I aim to call the headlines of a blueprint sections in order to caption the different page types of the displayed content. My template does not work yet.
<?= page('works')->blueprint()->sections('paintings')['headline'][$kirby->language()->code()] ?>```
Undefined array key "headline"
How can I achieve this?
tillcremer:
page('works/painting')-
Looks like this doesn’t return a page object. Make sure to pass the complete path to the page.
It is also best practice to check if a page exists:
if ($p = page('works/painting') ) {
echo $p->blueprint()->title();
}
Well, the page Works collects different types of works such as paintings, polyptychs, editions. The blueprint is:
sections:
paintings:
headline:
de: Gemälde
en: Paintings
type: pages
template: painting
polyptychs:
headline:
de: Polyptycha
en: Polyptychs
type: pages
template: polyptych
editions:
headline:
de: Editionen
en: Editions
type: pages
template: edition
In my template, I aim to show the headlines
using this code:
<?= page('works')->blueprint()->sections('paintings')['headline'][$kirby->language()->code()] ?>
Again, you should make sure the page exists (unless you are 100% sure this page has no chance to disappear through deleting, renaming etc.).
And in your blueprint you show sections but are trying to get a non-existing field.
But your second example is different from your first…
Thank you. I have no idea how to use this code:
if ($p = page('works/painting') ) {
echo $p->blueprint()->title();
}
Anyways, the page Works exists.
Please see the revised examples above. I just want to call different section headlines in my template, regarding the chosen language.
<?php
if( $p = page('works') ) {
$p->blueprint()->section('paintings')->headline();
}
?>
Kirby automatically picks the right language, it seems.
1 Like
I changed headline
to label
. Now, it works.
My blueprint:
fields:
paintings:
label:
de: Gemälde
en: Paintings
type: pages
template: painting
polyptychs:
label:
de: Polyptycha
en: Polyptychs
type: pages
template: polyptych
editions:
label:
de: Editionen
en: Editions
type: pages
template: edition
My template:
<?= page('works')->blueprint()->field('paintings')['label'][$kirby->language()->code()] ?>
P.S. I am always confused with fields and sections and do not get the difference since both seem to mostly work.
But now you have changed sections to field, that’s quite another story. Also, the template
property now doesn’t make sense anymore.
1 Like
What do you suggest? Is it possible to show and translate the headlines of the sections as I did with the labels of the fields?
I already posted my solution above… I don’t know if you need fields or section, I just wanted to point out that it’s a big difference. Pages fields are select fields where you select pages out of a given set. You cannot create new pages from a pages field, and the result is stored in the content file.
Dear @pixelijn , thank you so much. Finally, I achieved my goal to show the sections’ headlines. I guess I missed this post from you. It works with:
<?= page('works')->blueprint()->section('paintings')->headline() ?>