withastro / astro

The web framework for content-driven websites. ⭐️ Star to support our work!
https://astro.build
Other
47.25k stars 2.51k forks source link

🐛 BUG: Frontmatter variables in Markdown #3318

Closed ClintH closed 2 years ago

ClintH commented 2 years ago

What version of astro are you using?

1.0.0-beta.27

Are you using an SSR adapter? If so, which one?

None

What package manager are you using?

npm

What operating system are you using?

Linux

Describe the Bug

Seems the same issue as #2886 ?

---
notworking: working

---

![foo]({frontmatter.notworking})

Yields HTML:

<img src="%7Bfrontmatter.notworking%7D" alt="foo">

Expected HTML:

<img src="working" alt="foo"> 

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-9qfe1m-wef4od?file=src%2Fpages%2Findex.md,package.json

Participation

natemoo-re commented 2 years ago

Does it works this way in MDX? I personally wouldn't expect this syntax to work.

The following should work with an explicit img tag, though.

---
notworking: working
---

<img src={frontmatter.notworking} alt="foo" />
ClintH commented 2 years ago

I suppose I expected variables to work consistently as per the variables in Markdown documentation.

One might argue that the syntax is the MD equivalent for the IMG tag example you give. Having to use HTML or fancy components would be a shame as it diminishes the point of using Markdown.

RichardJECooke commented 1 year ago

Could someone from Astro please explain how frontmatter variables are supposed to work?

None of the examples render the variable value for me in the output:

A link - [{frontmatter.url}]({frontmatter.url})

In backquotes - `{frontmatter.technology}`

In codeblocks -  

'''
git clone {frontmatter.url}.git
cd fusionauth-quickstart-wordpress-web
'''

What syntax do I use to get these to render? Otherwise I have to copy and paste their values dozens of times throughout my document, and update every one manually whenever I change them.

RichardJECooke commented 1 year ago

This doesn't render:

<a href="{frontmatter.url}">{frontmatter.url}</a>

But this does:

<a href={frontmatter.url}>{frontmatter.url}</a>

tambuildsthings commented 5 months ago

In case others find this thread as I did - my mistake was using .md files and not .mdx files. With .mdx files and the MDX extension installed I can now use frontmatter variables directly in the markdown using {frontmatter.variable_name}.