Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions create/reusable-snippets.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
keywords: ["content snippets", "reusable content", "variables"]
---

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.

Check warning on line 7 in create/reusable-snippets.mdx

View check run for this annotation

Mintlify / Mintlify Validation (mintlify) - vale-spellcheck

create/reusable-snippets.mdx#L7

Spell out 'DRY', if it's unfamiliar to the audience.

Check warning on line 7 in create/reusable-snippets.mdx

View check run for this annotation

Mintlify / Mintlify Validation (mintlify) - vale-spellcheck

create/reusable-snippets.mdx#L7

Use parentheses judiciously.

Snippets do not render as standalone pages. You must import them into other files.

Check warning on line 9 in create/reusable-snippets.mdx

View check run for this annotation

Mintlify / Mintlify Validation (mintlify) - vale-spellcheck

create/reusable-snippets.mdx#L9

Use 'don't' instead of 'do not'.

## Configure snippet folders
## Configure snippet locations

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`.
By default, any file in a folder named `snippets` is treated as a snippet. You can place snippets anywhere in your project by configuring custom locations with the `snippets` field in your `docs.json`.

Add [glob patterns](https://code.visualstudio.com/docs/editor/glob-patterns) to the `snippets` array in `docs.json` to specify which folders contain snippets.
Add [glob patterns](https://code.visualstudio.com/docs/editor/glob-patterns) to the `snippets` array in `docs.json` to specify which folders or files should be treated as snippets. The default `/snippets/` folder remains supported even when you add custom patterns.

Check warning on line 15 in create/reusable-snippets.mdx

View check run for this annotation

Mintlify / Mintlify Validation (mintlify) - vale-spellcheck

create/reusable-snippets.mdx#L15

In general, use active voice instead of passive voice ('be treated').

```json docs.json
{
Expand All @@ -24,6 +24,12 @@
}
```

In this example:
- All files in the `components` folder and its subfolders are snippets

Check warning on line 28 in create/reusable-snippets.mdx

View check run for this annotation

Mintlify / Mintlify Validation (mintlify) - vale-spellcheck

create/reusable-snippets.mdx#L28

Did you really mean 'subfolders'?
- All files in the `shared/reusable` folder and its subfolders are snippets

Check warning on line 29 in create/reusable-snippets.mdx

View check run for this annotation

Mintlify / Mintlify Validation (mintlify) - vale-spellcheck

create/reusable-snippets.mdx#L29

Did you really mean 'subfolders'?
- The specific file `shared/common-component.mdx` is a snippet
- Files in the default `/snippets/` folder are still snippets

## 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.
Expand Down Expand Up @@ -143,7 +149,7 @@
```

<Note>
When creating JSX snippets, use arrow function syntax (`=>`) rather than function declarations. The `function` keyword is not supported in snippets.

Check warning on line 152 in create/reusable-snippets.mdx

View check run for this annotation

Mintlify / Mintlify Validation (mintlify) - vale-spellcheck

create/reusable-snippets.mdx#L152

Use 'isn't' instead of 'is not'.
</Note>

2. Import the snippet.
Expand Down