Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add data pops in ContentRendererMarkdown and varaibles binding #2360

Merged
merged 3 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 39 additions & 0 deletions docs/content/2.usage/2.markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,45 @@ In addition to mdc components and `span`, attribute syntax will work on images,
::
::

## Binding Data in Markdown

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.

### Example 1: Define in YAML

```md
---
title: 'Title of the page'
description: 'meta description of the page'
customVariable: 'Custom Value'
---

# The Title is {{ $doc.title }} and customVariable is {{ $doc.customVariable }}

```

### Example 2: Define in external with `<ContentRendererMarkdown>`

```html
<template>
<div>
<ContentRendererMarkdown :value="data" :data="mdcVars"/>
<button type="button" v-on:click="mdcVars.name = 'Hugo'">Change name</button>
</div>
</template>

<script setup lang="ts">
const { data } = await useAsyncData(() => queryContent('test').findOne());
const mdcVars = ref({ name: 'Maxime'});
</script>
```

```md

# Hello {{ $doc.name }}

```

## Prose Components

In Nuxt Content, the prose represents HTML tags generated by the Markdown syntax, such as title levels and links.
Expand Down
3 changes: 3 additions & 0 deletions docs/content/4.components/2.content-renderer.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ Other types will currently be passed to default slot via `v-slot="{ data }"` or
- `components`: The map of custom components to use for rendering. This prop will pass to markdown renderer and will not affect other file types.
- Type: `object`
- Default: `{}`
- `data`: A map of variables to inject into the markdown content for later use in binding variables.
- Type: `object`
- Default: `{}`

## Slots

Expand Down