Insert frontmatter property in markdown body in Astro

172 views Asked by At

I have this frontmatter heading a .md file in Astro.

---
title: A great movie
director: John Doe
---

I thought that a syntax like [actor], or {{actor}}, or {frontmatter.actor} or something similar would allow me use the properties as variables INSIDE the markdown body and they will be rendered with the proper values.

---
title: A great movie
director: John Doe
---

## My thoughts about {{actor}}

We all know the great director {{director}} and we have seen all his films.

Isn't it possible?

1

There are 1 answers

2
mb21 On BEST ANSWER

After installing the Astro MDX integration with:

npx astro add mdx

you can use the following syntax in any .mdx file:

---
layout: '../../layouts/BlogPostLayout.astro'
title: A great movie
director: John Doe
---

## My thoughts about {frontmatter.title}

We all know the great director {frontmatter.director} and his films.