How snippets work
Snippets are any.mdx, .md, or .jsx files imported into another file. You can place snippet files anywhere in your project.
When you import a snippet into another file, the snippet only appears where you import it and does not render as a standalone page. Any file in the /snippets/ folder is always a snippet even if it is not imported into another file.
Create snippets
Create a file with the content you want to reuse. Snippets can contain all content types supported by Mintlify and they can import other snippets.Import snippets into pages
Import snippets into pages using either an absolute or relative path.- Absolute imports: Start with
/for imports from the root of your project. - Relative imports: Use
./or../to import snippets relative to the current file’s location.
Import text
-
Add content to your snippet file that you want to reuse.
shared/my-snippet.mdx
-
Import the snippet into your destination file using either an absolute or relative path.
Import variables
Reference variables from a snippet in a page.-
Export variables from a snippet file.
shared/custom-variables.mdx
-
Import the snippet from your destination file and use the variable.
destination-file.mdx
Import snippets with variables
Use variables to pass data to a snippet when you import it.-
Add variables to your snippet and pass in properties when you import it. In this example, the variable is
{word}.shared/my-snippet.mdx -
Import the snippet into your destination file with the variable. The passed property replaces the variable in the snippet definition.
destination-file.mdx
Import React components
-
Create a snippet with a JSX component. See React components for more information.
components/my-jsx-snippet.jsx
When creating JSX snippets, use arrow function syntax (
=>) rather than function declarations. The function keyword is not supported in snippets.-
Import the snippet.
destination-file.mdx