Hi
I just read through this: Fetching field options | Kirby CMS and I was wondering if there is a similarly elegant way to access the field options in blocks, not pages.
What I’d like to do is to add an alt text to an icon/image that uses the description used in the Panel:
Snippet from blueprint:
…
fields:
icon:
type: select
label: Ikone
width: 1/2
options:
burger: Hambuger-Menü
email: E-Mail / Briefumschlag
external-link: Externer Link / Teilen
phone: Telefon
x: X / Schließen / Nein
However I’m getting an error, leading me to assume the code examples can’t just be modified to use $block instead of $page:
Block error: "Cannot use object of type Kirby\Content\Field as array" in block type: "button"
One more thing:
The site is prepared for translation and configured for multi-language support, but the blueprints only have labels in one language at the moment. That is why the blueprint snippet looks like a single-language site, and the PHP snippet fetches the language-code. I already tried using the non-multi language option from the cookbook page linked above, thinking it might be because the blueprint isn’t translated.
I found an answer for Kirby 3, but I’m posting this question in the hope that this might have changed in Kirby 4 and the solution is outdated.
Thanks for confirming I’ve decided to approach this problem from a different angle and I have a sort of related question:
The new solution:
I now allow users to upload icon SVG files via the panel globally on $site. This way the files can have their own file-blueprint with an alt-field.
On the usage side, the select that allows users to pick an icon, uses a query now:
Thanks, both of that helped. Sorry I didn’t get back to this earlier! The reason I didn’t use a files-field is that I didn’t think of it… thanks for suggesting it!
I switched to a files-field to show a preview—works great! However, I seem not to grasp how to use the text-property of the files-field.