Skip to content

Commit 1d84f0a

Browse files
authored
docs: add data pops in ContentRendererMarkdown and varaibles binding (#2360)
1 parent 9ec555e commit 1d84f0a

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

docs/content/2.usage/2.markdown.md

+39
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,45 @@ In addition to mdc components and `span`, attribute syntax will work on images,
458458
::
459459
::
460460

461+
## Binding Data in Markdown
462+
463+
You can bind data within your Markdown document using the `{{ $doc.variable }}` syntax. These values can be defined in the YAML front matter at the top of the document, within each MDC component, or injected using the `data` prop of the `<ContentRendererMarkdown>` component.
464+
465+
### Example 1: Define in YAML
466+
467+
```md
468+
---
469+
title: 'Title of the page'
470+
description: 'meta description of the page'
471+
customVariable: 'Custom Value'
472+
---
473+
474+
# The Title is {{ $doc.title }} and customVariable is {{ $doc.customVariable }}
475+
476+
```
477+
478+
### Example 2: Define in external with `<ContentRendererMarkdown>`
479+
480+
```html
481+
<template>
482+
<div>
483+
<ContentRendererMarkdown :value="data" :data="mdcVars"/>
484+
<button type="button" v-on:click="mdcVars.name = 'Hugo'">Change name</button>
485+
</div>
486+
</template>
487+
488+
<script setup lang="ts">
489+
const { data } = await useAsyncData(() => queryContent('test').findOne());
490+
const mdcVars = ref({ name: 'Maxime'});
491+
</script>
492+
```
493+
494+
```md
495+
496+
# Hello {{ $doc.name }}
497+
498+
```
499+
461500
## Prose Components
462501

463502
In Nuxt Content, the prose represents HTML tags generated by the Markdown syntax, such as title levels and links.

docs/content/4.components/2.content-renderer.md

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ Other types will currently be passed to default slot via `v-slot="{ data }"` or
2323
- `components`: The map of custom components to use for rendering. This prop will pass to markdown renderer and will not affect other file types.
2424
- Type: `object`
2525
- Default: `{}`
26+
- `data`: A map of variables to inject into the markdown content for later use in binding variables.
27+
- Type: `object`
28+
- Default: `{}`
2629

2730
## Slots
2831

0 commit comments

Comments
 (0)