I have been asked to add a FAQS to several pages, but also make it so the sections are collapsable. Although I could hard code this in HTML, I would rather avoid doing this and instead have it specified in a Markdown document and then have it transformed.
What I had considered doing is adding a content section “content/faq” and then adding the individual FAQs as markdown formatted docs in that page. Then the markdown could be included and processed as appropriate.
An example markdown I had considered:
### This is a question
This is an answer,
- list A
- list B
### This is another question
This is another answer
With the output being something along the lines:
<div class="faq-entry">
<div class="faq-entry-question">This is another question</div>
<div class="faq-entry-answer">This is another answer</div>
</div>
Could this approach work, and if so how could I include and transform it? If not, what other suggestions are there?
The one issue I have here is that I am not sure how add list items and paragraphs to items in definition section. In the mean time I’ll play around with what you shared.
You can use Javascript for any kind of collapsible script using the .faq-answer class.
Now, having done that, you could add structured data to your shortcode to excel in the SEO department. Something I am planning for a while but not having time to
If yes, you can define a custom content/page type, pick two tags to sacrifice, and bend them beyond recognition in custom CSS to your needs. If you need to wrap each Q/A pair in a block element, you can use > for that (translates into <blockquote>).
That’s ugly, but allows to avoid shortcodes in Markdown.
This approach allows you to tag and categorize (taxonomies), provide metadata (front matter), display a subset (using where), control the order in which they are displayed, make a few of them “sticky” at the top of lists, etc.
If you only have a handful of FAQs on the site, this approach is probably overkill, but it is largely future proof due to its extensibility.
I would make it a bit more elaborate instead, as it is a perfect case for page bundle resources. Just add index.md and loop through page resources. Or add _index.md, and make it a section. That’s what it is usually called, the FAQ section.
If a single FAQ page doesn’t have to sit in a single file, of course.