# Reusable snippets

> Single source your documentation with reusable, custom markdown snippets to keep content in sync. Edit once, update everywhere.

Keep your documentation DRY (Don't Repeat Yourself) with single sourcing: define a reusable Markdown snippet once, and then reference 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.

<Steps>
  <Step title="Create file structure">
    Create a folder called `snippets` anywhere in your `fern` project. Inside the `snippets` folder, create a new Markdown file for each snippet you want to define.

    <Files>
      <Folder name="fern" defaultOpen>
        <Folder name="pages" defaultOpen>
          <File name="my-tutorial.mdx" highlighted />
        </Folder>

        <Folder name="assets" />

        <Folder name="snippets" defaultOpen>
          <File name="herbs.mdx" highlighted />

          <File name="peace-lily.mdx" highlighted />

          <File name="trees.mdx" highlighted />
        </Folder>
      </Folder>
    </Files>
  </Step>

  <Step title="Create a snippet">
    In each snippet file, define the content you want to reuse.

    ```mdx title="snippets/peace-lily.mdx"
    Peace lilies are easy to grow and relatively trouble-free.
    ```
  </Step>

  <Step title="Add parameters to snippets (optional)">
    To make snippets more flexible, you can use parameters (also called variables). Parameters use the `{{parameterName}}` syntax and can be placed anywhere in your snippet content.

    ```mdx title="snippets/watering-schedule.mdx"
    <Warning>Remember to water your {{plant}} every {{interval}} days.</Warning>
    ```

    You can then pass different values to these parameters each time you use the snippet.
  </Step>

  <Step title="Use a snippet">
    To use a snippet in your documentation, reference it by its file path (including the `.mdx` extension). If you used parameters (variables) in your snippet, pass values for each parameter:

    <Tabs>
      <Tab title="Markdown">
        <div>
          ```jsx
          <Markdown src="/snippets/peace-lily.mdx">

          They symbolize peace and prosperity.

          <Markdown src="/snippets/watering-schedule.mdx" plant="peace lily" interval="3">
          ```
        </div>
      </Tab>

      <Tab title="Preview">
        Peace lilies are easy to grow and relatively trouble-free.

        They symbolize peace and prosperity.

        <Warning>
          Remember to water your peace lily every 3 days.
        </Warning>
      </Tab>
    </Tabs>

    <Note title="File paths">
      The `src` path is an absolute path that takes the `fern` folder as the root. The path is the same no matter which page you're referencing it from:

      | Folder structure                           | Reference                                    |
      | ------------------------------------------ | -------------------------------------------- |
      | `fern/snippets/peace-lily.mdx`             | `src="/snippets/peace-lily.mdx"`             |
      | `fern/docs/snippets/peace-lily.mdx`        | `src="/docs/snippets/peace-lily.mdx"`        |
      | `fern/docs/guides/snippets/peace-lily.mdx` | `src="/docs/guides/snippets/peace-lily.mdx"` |
    </Note>
  </Step>
</Steps>