Skip to main content
One of the core principles of software development is DRY (Don’t Repeat Yourself). This is a principle that applies to documentation as well. If you find yourself repeating the same content in multiple places, you should consider creating a custom snippet to keep your content in sync.

Creating a custom snippet

Prerequisite: Create your snippet file in the snippets directory.
Mintlify treats any page in the snippets directory as a snippet and does not render it as a standalone page. To create a standalone page from the snippet, import the snippet into another file and call it as a component.

Default export

  1. Add content to your snippet file that you want to reuse across multiple locations. Optionally, add variables that you fill in with props when you import the snippet.
snippets/my-snippet.mdx
The content that you want to reuse must be inside the snippets directory in order for the import to work.
  1. Import the snippet into your destination file.
destination-file.mdx

Reusable variables

  1. Export a variable from your snippet file:
snippets/path/to/custom-variables.mdx
  1. Import the snippet into your destination file and use the variable:
destination-file.mdx

Reusable components

  1. Inside your snippet file, create a component that takes in props by exporting your component in the form of an arrow function.
snippets/custom-component.mdx
MDX does not compile inside the body of an arrow function. Stick to HTML syntax when you can or use a default export if you need to use MDX.
  1. Import the snippet into your destination file and pass in the props.
destination-file.mdx