Skip to content

ButterIX v1 is out: versions, multiple languages, Ask AI, and a per-site MCP server, all built in. →

Reusable snippets and variables

Write repeated content once and reference it everywhere — snippet files, parameterized snippets, page variables, and conditional content.

Snippet files

A snippet is just a regular .mdx / .md file that can contain any Markdown and components. By convention they live in the snippets/ directory at the project root. Here's this site's snippets/install-cli.mdx:

snippets/install-cli.mdx
<CodeGroup>
```bash npm
npm install -g bitidocs
```

```bash pnpm
pnpm add -g bitidocs
```

```bash yarn
yarn global add bitidocs
```
</CodeGroup>

Reference with a component

<Markdown src="/snippets/install-cli.mdx" />
npm install -g bitidocs

<Snippet> and <Include> are aliases of <Markdown>; the path prop can also be written as file or path. Path resolution rules:

SyntaxResolves to
/snippets/x.mdx (or @/snippets/x.mdx)A path under the project root
./x.mdx, ../shared/x.mdxRelative to the current file
x.mdxsnippets/x.mdx at the project root

Reference with import

You can also import a snippet and use it as a component:

import InstallCli from "/snippets/install-cli.mdx"

<InstallCli />

Only .md / .mdx files can be imported, and only default imports are supported; importing a JavaScript module reports an mdx/import error. Snippets can reference other snippets in turn (up to 5 levels deep).

Parameterized snippets

Extra props passed to a snippet replace placeholders in the snippet body. Since {…} is an expression in MDX, placeholders in snippets must be escaped as \{name\}:

snippets/node-requirement.mdx
<Info title="环境要求 · Requirements">
  Node.js ≥ \{node\} · `biti --version` ≥ \{cli\}
</Info>
<Markdown src="node-requirement.mdx" node="22.13" cli="0.1.0" />
环境要求 · Requirements

Node.js ≥ 22.13 · biti --version ≥ 0.1.0

Placeholders without a passed-in value are shown as-is.

If you write an unescaped {node} directly in a snippet, MDX evaluates it as an expression; node isn't a known variable, so the expression is dropped with an mdx/expression warning, and no replacement can happen.

Page variables

Declare literals with export const at the top of the page, then use them in the body or in component props:

export const cliVersion = "0.1.0"
export const minNode = "22.13"

The current CLI version is {cliVersion} and requires Node.js {minNode} or later.

<Badge intent="success">{"v" + cliVersion}</Badge>

The current CLI version is 0.1.0 and requires Node.js 22.13 or later.

v0.1.0

Variable values can only be literals: strings, numbers, booleans, arrays, plain objects, template strings, plus + concatenation between them, ternary expressions, and member access (such as {plans.pro.price}). Functions, classes, regular expressions, and any calls are not allowed; see Safe subset.

Conditional content

<If> (alias <Conditional>) decides whether to render content based on the locale, version, or product of the current page, without producing a wrapper element. It's especially useful when a snippet is shared across locales or versions:

<If locales={["zh"]}>
  This text only appears on Chinese pages.
</If>

<If versions={["v0"]}>
  You're reading the legacy docs.
</If>

<If versions={["v0"]} not>
  This only appears outside v0.
</If>
You are reading the English version.
localesstring[]
Locale codes, e.g. ["en", "zh"].
versionsstring[]
Version ids, slugs, or display names.
productsstring[]
Product ids, slugs, or display names.
notboolean
Negate the condition.
rolesstring[]
Show content by reader role. Static sites have no signed-in users, so conditions with roles never match.

Snippets and translations

Snippet files aren't split by locale: Chinese and English pages reference the same file. When you need multiple locales, there are two approaches:

  1. Keep locale-specific text in the pages, and put only locale-independent content such as code in snippets (like this site's install-cli.mdx).
  2. Wrap paragraphs for different locales in <If locales> inside the snippet.