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

Using Variables that exist in the YAML or JSON files inside your markdown. #88

Closed
andyfensham opened this issue Jun 3, 2020 · 3 comments
Labels
question Further information is requested

Comments

@andyfensham
Copy link

Is it possible to use the variables that comes from the YAML def or the JSON files or CSV files inside your markdown on a specific page.

In an index page I can go and fetch all the content of a specific folder inside the contents directory. I can list the content and then route to a specific page for e.g. markdown. But I want to use the same variables that was available when I received the content through this.$content inside the actual markdown page instead of manually typing it.

@andyfensham andyfensham added the question Further information is requested label Jun 3, 2020
@benjamincanac
Copy link
Member

Hey @andyfensham,

When using nuxt-content component, all the document variables are injected inside the markdown, so you can do for example:

---
title: Introduction
src: https://content.nuxtjs.org/icon.png
---

<img :src="src"></img>

@crazymind
Copy link

crazymind commented Dec 10, 2020

@benjamincanac

What would be the solution here, if you try display a variable not in a html attribute?
This for an example won't work:

---
title: Introduction
src: https://content.nuxtjs.org/icon.png
---
 
<h1>{{ title }}</h1>

pi0 pushed a commit that referenced this issue Feb 8, 2022
Co-authored-by: Yaël Guilloux <yael.guilloux@gmail.com>
pi0 pushed a commit that referenced this issue May 5, 2022
@nwittwer
Copy link

nwittwer commented Jul 10, 2022

@crazymind As far as I can tell, there isn't a solution for interpolating these frontmatter YML variables within the document in Nuxt Content v1, i.e. {{ title }} should become Introduction once compiled, but currently it just shows {{ title }} still.

It does look like this is coming to Nuxt Content v2, along with a new MDC (Markdown Components) format. Looks like the PR has been merged, but is not yet released as of v2.0.1: #1266

That being said, it would be really great to see the frontmatter variable interpolation in Nuxt Content v1 as well. Nuxt v2 + Content v2 are not yet stable and documented enough for the static site use case I have.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants