Good afternoon!
I declare myself to be a Kirby Newcomer so please forgive me if I am asking something obvious. But I cannot wrap my head around the best way forward for the following use-case:
On our website there will be a FAQ, consisting of several sections with several questions per section. The FAQ will be multilingual.
Would I would like to do now is store all FAQ entries in one “container” (page?) and be able to display FAQ entries for specific or all categories on several pages.
So for example I have my contact us page. There I would like to display all questions of the category “how to contact us”. On my product page I would like to display all questions of the categories “Questions about products” and “How to contact us”.
So I would somehow need to store all question <> answer <> category data in one file and then be able to “querey” these including a select/filter of categories (and thus questions) on an individual page level.
(How) is this possible with Kirby?
Thanks
Andreas
I’d say it depends.
For a multilingual setup, it might even make sense to create subpages for each question to make sure that questions and translations are in line.
With structure fields or blocks to handle such FAQ, a multi-language approach might get out of sync, unless you handle all languages within the default language (and then later filter per language on the frontend).
In general, assigning a category to each individual question might be the easiest approach. Then you can later filter all FAQ by these categories.
Thanks for your always quick reply @texnixe ![:+1: :+1:](https://emoji.discourse-cdn.com/apple/+1.png?v=12)
When posting this, I wanted to avoid having subpages for each question because currently I build the site of from scratch manually. But if I would use the panel for this, the experience of maintaining these questions would be better I guess.
But still, having potentially dozens of questions times x languages sounds a lot of files for me. What do you think about using an excel-sheet/CSV file with virtual pages? It would have a row for each question/answer pair plus a column for the category and the translations.
But then again, using an excel sheet for such a thing in 2023 hurts my pride ![:grin: :grin:](https://emoji.discourse-cdn.com/apple/grin.png?v=12)
The alternative to the alternative would be to use a proper database and query it via API. But I dont like this one because it affects the performance potentially. Kirby is super quick and calling APIs takes more time.
I am unsure ![:slight_smile: :slight_smile:](https://emoji.discourse-cdn.com/apple/slight_smile.png?v=12)
I don’t think an Excel Sheet or database is a good idea for this, you will not have hundreds of questions and it means going to another medium just to edit a question.
But from a handling point of view, the subpages approach is the easiest to handle, because:
Let’s say you use a blocks field with a custom FAQ item block. You create all FAQ in the default language. Then you head over to the second language and translate everything. All good until this point.
But if you add another entry, it will not automatically show up in the translated language, so you have to go to the second language and add the block there together with the translation.
I have literally no experience with blocks yet but from what I have read and what you are telling me you are right of course.
Thanks, I will sleep over it but I guess subpages it is!
Andreas
@texnixe may I ask you for your help again please? I am using the groupBy function as per your example to get this to work but the groupBy function does not group ![:slight_smile: :slight_smile:](https://emoji.discourse-cdn.com/apple/slight_smile.png?v=12)
This is my content folder structure:
![image](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/2X/1/1b45036329c1c84625f6af698a6026fd4b16f90f.png)
(I have not setup a template for this page)
This is how each faq.xx.txt looks like:
Category: Products
Question: How many do you have?
Answer: We have lots of products
Now when I run this code:
// Group all questions per category
$categories = page('faq')->children()->groupBy('category');
// First we loop through the categories and echo the category
foreach($categories as $category => $questionsPerCategory): ?>
<div>
<h4><?= $category ?></h4>
<ul>
<?php
// Then we loop through all the questions for each category
foreach($questionsPerCategory as $question) : ?>
<li>Q: <?= $question->question() ?></li>
<li>A: <?= $question->answer() ?></li>
<?php endforeach; ?>
</ul>
</div>
<?php endforeach ?>
What happens is that there is no grouping by category but rather the each question text file is outputted in $category as a string - ergo the next foreach loop outputs nothing.
Very strange. What am I doing wrong?
Thanks
Andreas
Really without dashes between the fields?
Wow, that really is embarrassing.
But to my defense: I only slept 4 hours last night.
Maybe I should have taken the break I announced ![:slight_smile: :slight_smile:](https://emoji.discourse-cdn.com/apple/slight_smile.png?v=12)
![:speak_no_evil: :speak_no_evil:](https://emoji.discourse-cdn.com/apple/speak_no_evil.png?v=12)