Reusing content with variables
Content variables hold short shared strings, like product names, support addresses, company names. If you edit the wording once, each topic that uses these variables stays in sync.
In this template, you can find variables under docs/_variables/. There are two patterns:
| Pattern | When to use | Mechanism |
|---|---|---|
| Fixed (no override) | The value must be the same everywhere | Import a named export from defaults.js |
| Default with override | Most places use the site default, but one page needs a different value | Use the Var component, and optionally pass value |
For larger reused blocks (notices, tips), see Reusing content with includes.
Fixed variables (no override)
Use this when a string must never differ by page, for example, a legal company name or the canonical product name.
-
Open
docs/_variables/defaults.jsand add or edit a named export:docs/_variables/defaults.jsexport const productName = '3di Docusaurus Template';export const supportEmail = 'docs@example.com';export const companyName = '3di Information Solutions'; -
In the topic (
.mdx), import the names you need after the front matter:import {productName, supportEmail} from '@site/docs/_variables/defaults.js'; -
Insert the value in the body with curly braces.
In plain text or JSX attributes,{supportEmail}resolves to the string. Markdown link destinations do not — use an<a>tag formailto:links:Contact <a href={`mailto:${supportEmail}`}>{supportEmail}</a> about {productName}.
Live example (fixed)
Contact docs@example.com about 3di Docusaurus Template (3di Information Solutions).
Variables with an optional override
Use this when the site has a default, but a specific topic may need a different string for that one insertion.
-
Keep the defaults in
docs/_variables/defaults.jsas above. -
Import the
Varcomponent:import Var from '@site/docs/_variables/Var.js'; -
Place
<Var />where the string should appear.
Thenameprop must match an export indefaults.js:Configure <Var name="productName" /> before you publish. -
To override for this use only, add a
valueprop:Configure <Var name="productName" value="Billing API" /> before you publish.Omit
valueto keep the site default. The override applies only to that tag; other pages are unchanged.
Live examples (override)
- Default: Configure 3di Docusaurus Template before you publish.
- Overridden on this page only: Configure Billing API Docs before you publish.