I have a set of custom fields in my blueprints. Is there a way to display the title/label of a blueprint field conditionally?
Suppose I have:
year:
label: Year/Jaar
type: text
How can I get to show ‘Year/Jaar’? Something like <?php echo $page->year()->label() ?>, does that exist? Obviously I can use html to put it in my template, but the thing is I would like to show it conditionally only when the field is actually filled in.
Can somebody help out?
You can’t get the label of a field, because it only exists in the panel, not in the text file. However, you could still do it conditionally (at least if I got you right)
Kirby has a field method to check if it’s not empty: In this case it would be:
$page->year()->isNotEmpty()
As for language-specific labels, you could use this in your blueprint:
year:
label:
en: Year
nl: Jaar
type: text
But you would need to enable multi-language support in order to use it, as it will only show the according field label when the language is switched in the panel.
The name of the field is not the same as the label, though.
In his case the key is client, but the label is Year/Jaar.
I think what @lsg wants is to display Year/Jaar, so unfortunately the key isn’t of any help here.
As for me, the code Texnixe wrote works perfectly! That is exactly what I meant…
Thanks!
Concerning the multilingual aspect, we have not yet decided which direction to take, but thank you for informing me on this possibility, I was not aware of that option!