nuxt / content

The file-based CMS for your Nuxt application, powered by Markdown and Vue components.
https://content.nuxt.com
MIT License
3k stars 605 forks source link

Accessing context/index of MDC #2612

Open chrisjansky opened 2 months ago

chrisjansky commented 2 months ago

Hello,

I am wondering if I can somehow access a dynamic index/context/etc when inside a Markdown Component.

I am building an according FAQ section using radix-vue Accordion which I would like to populate with MDC like so:

::question
How do I pay?
#answer
You pay like this.
::

::question
How is VAT collected?
#answer
VAT is collected like this.
::

The problem is, radix-vue <Accordion> needs a dynamic value to key the items and set the default opened <AccordionItem>.

Something simple like ::question{:index=$doc.index} would therefore work just fine. Has someone implemented a similar feature?

Thanks for any pointers.

farnabaz commented 5 days ago

You can define a variable in front matter and use it in component props:

---
index
---
::question{:index="index"}
How do I pay?
#answer
You pay like this.
::