content
content copied to clipboard
How to use Partials Documentation
Environment
------------------------------
- Operating System: Darwin
- Node Version: v18.18.2
- Nuxt Version: 3.7.4
- CLI Version: 3.9.0
- Nitro Version: 2.7.1
- Package Manager: [email protected]
- Builder: -
- User Config: ssr, imports, devtools, modules, content, runtimeConfig, components
- Runtime Modules: @nuxtjs/[email protected], @pinia/[email protected], @formkit/[email protected], @vueuse/[email protected], @nuxt/[email protected], [email protected]
- Build Modules: -
------------------------------
Reproduction
The Docs
Describe the bug
The docs don't mention what partials can be used for nor how to use them. I can imagine that they can be included in documents just like how Vitepress can inject documents. But when i tried that syntax it didn't work
Additional context
I opened an issue because this question was asked a while ago in the discussion and didn't receive any answer https://github.com/nuxt/content/discussions/2049
Logs
No response
Hello,
something like this: https://github.com/unjs/website/blob/main/components/home/HomeNoArticles.vue?
So it's just a way to render markdown text and not treat it as an Blog/Article/Page ? can a partial be injeccted in a Blog/Article/Page markdown file like Vitepress offer?
Ooh you talk about something like this! https://vitepress.dev/guide/markdown#markdown-file-inclusion I never try but could just be some plugins to add
Yes, as I pointed to the link in my original question. I have found this plugin https://github.com/dotansimha/remark-import-partial which looks great but i want to avoid using something like that if Nuxt/Content support such a behaviour out of the box. hence i am asking here.
Maybe @pi0 or @Atinux have some insights on this?
Yes, as I pointed to the link in my original question. I have found this plugin dotansimha/remark-import-partial which looks great but i want to avoid using something like that if Nuxt/Content support such a behaviour out of the box. hence i am asking here.
Maybe @pi0 or @Atinux have some insights on this?
There is no such behavior out of the box but content is parsed using remark. https://content.nuxt.com/get-started/configuration#markdown
FWIW: Here is my humble solution.
Partial.vue
<template>
<div>
<ContentRenderer :value="data">
<template #empty>
<p>No content found.</p>
</template>
</ContentRenderer>
</div>
</template>
<script setup lang="ts">
const props = defineProps({
content: {
default: "default"
}
});
const arg = ref(props.content);
const { data } = await useAsyncData(arg.value, () => queryContent('_partials/' + arg.value).where({ _partial: true }).findOne());
</script>
Whatever.md
[...]
<!--- Featured Services Grid --->
:::GlobalPartial{content=services-grid-2}
:::
[...]