Reusable Snippets

Keep your documentation DRY (Don’t Repeat Yourself) by defining a reusable snippet once, and then referencing it in multiple places. This way, you only need to update the snippet in one place to keep all references in sync.

Create a reusable snippet

To use reusable snippets, start by creating a new folder in your fern project called snippets. Inside the snippets folder, create a new file for each snippet you want to define.

For example:

$fern
>└─ pages
> └─ my-tutorial.mdx
>└─ assets
>└─ snippets
> ├─ herbs.mdx
> ├─ peace-lily.mdx
> └─ trees.mdx

In each snippet file, define the content you want to reuse. For example, peace-lily.mdx might contain:

snippets/peace-lily.mdx
1<Warning> Remember to water your plant at least twice a week. </Warning>

Use a reusable snippet

To use a snippet in your documentation, reference it by its file path (including the .mdx extension) in your content. For example, to include the peace-lily snippet in your content, use:

pages/my-tutorial.mdx
1---
2title: Getting started with your peace lily
3description: Peace lily care tips for beginners
4---
5
6## Caring for your new plant
7
8Peace lilies are easy to grow and relatively trouble-free.
9
10<Markdown src="../snippets/peace-lily.mdx" />