Writing Content

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:

>└── 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:

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 name (without the .mdx extension) in your content. For example, to include the peace-lily snippet in your content, use:

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