Allow users to change field label and calling field label in template


is there a way to allow users to change field labels when adding a page?

Is there a way to call field labels in a template?


You can use Kirby query language to set the label, so yes, users could define those field labels somewhere.

Yes, via $page->blueprint() see docs and

1 Like

Dear @texnixe,

I found your post about a similar topic. My code

<?php $page->blueprint()->field('data')['fields']['period']['label'] ?>

results in

Whoops\Exception\ErrorException thrown with message “Undefined index: fields”

and I don’t know what’s wrong. The blueprint excerpt:

    	type: fields
            	label: Period of Origin
            	type: text

Do you have an idea how I can make it work?

Besides, I wonder if it’s possible to let the user change a field’s label in the panel.

data is the name of your section, the field is call period, so it should be

$field = $page->blueprint()->field('period');
$label = $field['label'];

As regards a dynamic label, you can query data from other locations

  label: "{{page.parent.someFieldThatContainsTheLabel}}"
  type: text

This could also be done in a structure field where multiple labels could be defined


Now it works. Thank you very much! :upside_down_face: My template code:

<?= $page->blueprint()->field('period')['label'] ?>

It’s possible to edit page titles directly. I intend to enable the user to edit and change field labels the same way. Is that even possible, @texnixe? Or is the indirect way you proposed the only possibility to let the user change field labels?

Bildschirmfoto 2021-02-26 um 19.29.38

Nope, that’s not possible. Wouldn’t really make sense, because where would you store this? The title is part of the content, the label of a field is not. And the label shouldn’t change from page to page but be the same across the same blueprint.

Thank you, I see. In my opinion, it would nevertheless be a great feature if it were possible to enable editors (theme users) to directly change field labels using the panel. As you can see in this screencast for instance, field labels can manually or automatically be part of content. As user interface designer and web developer, I would like to offer most flexible themes as related to content. Otherwise, an end user (content editor) needs a developer to change this part of the content. The indirect way described above is a solution but seems to be inconvenient and not very elegant to me; it’s a workaround. Kirby is a super clear system and that’s why I appreciate it. I think Kirby should offer a direct way and clear solution for this matter. What do you think, @bastianallgeier?

I think you are looking for a blueprint editor. Such a feature is on the wishlist for quite some time, but we have no ETA for it yet.

Thanks a lot, @texnixe, this solution fits perfectly for my current project. In my use case, there have to be different labels for some fields in different pages that all share the same blueprint. There is no requirement for dynamic user-definable labels, but rather a static correlation which field gets which label on which particular page. So this will easily be achieved by some configuration or constant arrays.