Reusable snippets

Keep your documentation DRY (Don’t Repeat Yourself) by defining a reusable Markdown 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.

Reusable snippets work well for constants (API limits, subscription prices, version numbers), repeated warnings or notes, and standardized formatting blocks.

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 Markdown 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:

1Peace lilies are easy to grow and relatively trouble-free.
2
3<Markdown src="/snippets/peace-lily.mdx">