Access site config in Docusaurus markdown doc

Viewed 598

I'm trying to configure custom configuration variables according to the docs.

I added the following section in the docusaurus.config.js

  customFields: {
    foo: 'bar',
  },

And in my .md file I have:

---
id: fake-id
title: Test
---

# Title

import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
const {siteConfig} = useDocusaurusContext();
<div>{siteConfig.customFields.foo}</div>;

The document does not render though. How can I access this variable in a doc markdown?

1 Answers

Have you tried changing your file from .md to .mdx? per Docusaurus docs:

While both .md and .mdx files are parsed using MDX, some of the syntax are treated slightly differently. For the most accurate parsing and better editor support, we recommend using the .mdx extension for files containing MDX syntax.

Related