I have a select field in the panel where I implemented translation directly in the blueprint like described in the docs.
In my case, the field are several categories for a FAQ stored as Question-Pages - like “About us” or “Service ABC”.
When displaying the FAQ categories in the FAQ template, I use a nested foreach loop to go through the categories and questions for each category:
// Group all questions per category
$categories = page('faq')->children()->groupBy('category');
foreach($categories as $category => $questionsPerCategory):?>
<div><h5><?= ucwords($category, " \t\r\n\f\v\-") ?></h5></div>
<?php $catID++; endforeach ?>
When I now output the $category, it always displays the definition of the select option as defined in the question page, not the translation (as it does in the panel).
Is there an easy way to access the translation? I tried the cookbook recipe for accessing field options but could not wrap my head around the idea of how to make this work without actually accessing the actual page.
Yes, that’s what you’d have to do, so get the translations from $category->blueprint(). Might make sense to only do this once. Or store what you have in your blueprint in the language translations and get it from there. Which would mean duplicating the work you have done in the blueprints, but I think the performance is better.
Thanks but this option is real ugly. I need to manually convert strings to uppercase because for whatever reason the category is outputted in lowercase but the array keys are not so that leads to things like
But if I were you, I’d go for translation variables and then use them also in your blueprint, like described in the docs: Select | Kirby CMS, second example.
That is why I have to use the ucwords stuff in the first place and that is why I would have to use it to be able to address the right key in the array.
I used upper case ones because I did not really think about the translations when doing this but you are right, this is the easiest fix. The nice looking version is stored in the translation anyway
I really love Kirby but the whole upper/lower-case thing is something I have issues with repeatedly g