You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
One of the core principles of software development is DRY (Don't Repeat
8
-
Yourself), which applies to documentation as
9
-
well. If you find yourself repeating the same content in multiple places, you
10
-
should create a custom snippet to keep your content in sync.
7
+
One of the core principles of software development is DRY (Don't Repeat Yourself), which applies to documentation too. If you find yourself repeating the same content in multiple places, create a custom snippet for that content. Snippets contain content that you can import into other files to reuse. You control where the snippet appears on a page. If you ever need to update the content, you only need to edit the snippet rather than every file where the snippet is used.
11
8
12
-
## Creating a custom snippet
9
+
Snippets do not render as standalone pages. You must import them into other files.
13
10
14
-
**Pre-condition**: You must create your snippet file in the `snippets` directory in order for the import to work.
11
+
## Configure snippet folders
12
+
13
+
By default, any file in a folder named `snippets` is treated as a snippet. You can configure additional custom folders to contain snippets with the `snippets` field in your `docs.json`.
14
+
15
+
Add [glob patterns](https://code.visualstudio.com/docs/editor/glob-patterns) to the `snippets` array in `docs.json` to specify which folders contain snippets.
16
+
17
+
```json docs.json
18
+
{
19
+
"snippets": [
20
+
"components/**",
21
+
"shared/reusable/**",
22
+
"shared/common-component.mdx"
23
+
]
24
+
}
25
+
```
26
+
27
+
## Create snippets
28
+
29
+
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.
30
+
31
+
## Import snippets into pages
32
+
33
+
To use snippets, import them into pages using either an absolute or relative path.
34
+
35
+
-**Absolute imports**: Start with `/snippets/` or your custom snippet location for imports from the root of your project.
36
+
-**Relative imports**: Use `./` or `../` to import snippets relative to the current file's location.
15
37
16
38
<Tip>
17
-
Snippets support both absolute imports (starting with `/snippets/`) and
18
-
relative imports (starting with `./` or `../`).
39
+
Relative imports enable IDE navigation. Press <kbd>CMD</kbd> and click a snippet name in your editor to jump directly to the snippet definition.
19
40
</Tip>
20
41
21
-
Any page in the `snippets` directory will be treated as a snippet and will not
22
-
be rendered into a standalone page. If you want to create a standalone page
23
-
from the snippet, import the snippet into another file and call it as a
24
-
component.
42
+
### Import text
25
43
26
-
### Default export
44
+
1. Add content to your snippet file that you want to reuse.
27
45
28
-
1. Add content to your snippet file that you want to re-use.
46
+
```mdx snippets/my-snippet.mdx
47
+
Hello world! This is my content I want to reuse across pages.
48
+
```
29
49
30
-
```typescript snippets/my-snippet.mdx
31
-
Hello world! This is my content I want to reuse across pages.
Copy file name to clipboardExpand all lines: customize/react-components.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -92,7 +92,7 @@ The counter renders as an interactive React component.
92
92
93
93
## Importing components
94
94
95
-
To import React components in your MDX files, the component files must be located in the `snippets` folder. You can then import them into any MDX page in your documentation. Learn more about [reusable snippets](/create/reusable-snippets).
95
+
To import React components in your MDX files, the component files must be located in a snippet folder. By default, this is the `/snippets/` folder. You can [configure additional directories](/create/reusable-snippets#configure-snippet-folders) to contain snippets in your `docs.json`. Learn more about [reusable snippets](/create/reusable-snippets).
Copy file name to clipboardExpand all lines: organize/settings.mdx
+10Lines changed: 10 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -643,6 +643,16 @@ This section contains the full reference for the `docs.json` file.
643
643
</Expandable>
644
644
</ResponseField>
645
645
646
+
<ResponseFieldname="snippets"type="array of strings">
647
+
Specify additional folders for reusable snippets using [glob patterns](https://code.visualstudio.com/docs/editor/glob-patterns). Any files in folders matching these patterns are snippets, in addition to the default `/snippets/` folder.
0 commit comments