Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions fern/products/docs/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ navigation:
path: ./pages/component-library/custom-components/reusable-markdown.mdx
- page: Custom React Components
path: ./pages/component-library/custom-components/custom-react-components.mdx
- page: Global Variables
hidden: true
path: ./pages/component-library/custom-components/global-variables.mdx
- section: Customization
collapsed: true
contents:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
---
title: Global Variables
---

<Warning>
Global variables are not yet available. Please contact [email protected] if you have any feedback or questions.
</Warning>

Global variables allow you to maintain consistency across your documentation and make updates easier by centralizing commonly used values. You can define and use global variables in several places within Fern documentation.

## Define global variables

Define global variables in your `docs.yml` file:

```yaml docs.yml
variables:
- name: "API_VERSION"
value: "v1"
- name: "API_URL"
value: "https://api.example.com"
```

## Use variables in content

Reference variables throughout your MDX content using double angle brackets:

### In Markdown

````mdx use-api.mdx
Use the latest version of the API: <<API_VERSION>>

```bash
curl -X GET <<API_URL>>/api/<<API_VERSION>>/users
```
````

### In API references

```yaml openapi.yml
paths:
/users:
get:
description: |
The API version is <<API_VERSION>>
responses:
'200':
description: "Success"
content:
application/json:
schema:
```

### In docs.yml configuration

You can also use variables in your `docs.yml` configuration.

```yaml docs.yml
variables:
- name: "ADMIN_ROLE_NAME"
value: "admin"
```

```yaml docs.yml
roles:
- everyone
- <<ADMIN_ROLE_NAME>>

navigation:
- tab: Admin
layout:
- page: Admin Dashboard
path: pages/admin-dashboard.mdx
viewers:
- <<ADMIN_ROLE_NAME>>
```

<Note>
Fern will not render variables in your content if they are not defined in your `docs.yml` configuration. Instead, the variable will be rendered as a literal string.
</Note>