Configure snippet folders
By default, any file in a folder namedsnippets is treated as a snippet. You can configure additional custom folders to contain snippets with the snippets field in your docs.json.
Add glob patterns to the snippets array in docs.json to specify which folders contain snippets.
docs.json
Create snippets
Create a file in a snippet folder 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
To use snippets, import them into pages using either an absolute or relative path.- Absolute imports: Start with
/snippets/or your custom snippet location 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.
snippets/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.
snippets/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}.
snippets/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.
snippets/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