Skip to content

Commit ad876f5

Browse files
authored
proposal: global variables (#299)
1 parent eb8f01e commit ad876f5

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

fern/products/docs/docs.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ navigation:
7979
path: ./pages/component-library/custom-components/reusable-markdown.mdx
8080
- page: Custom React Components
8181
path: ./pages/component-library/custom-components/custom-react-components.mdx
82+
- page: Global Variables
83+
hidden: true
84+
path: ./pages/component-library/custom-components/global-variables.mdx
8285
- section: Customization
8386
collapsed: true
8487
contents:
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
---
2+
title: Global Variables
3+
---
4+
5+
<Warning>
6+
Global variables are not yet available. Please contact [email protected] if you have any feedback or questions.
7+
</Warning>
8+
9+
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.
10+
11+
## Define global variables
12+
13+
Define global variables in your `docs.yml` file:
14+
15+
```yaml docs.yml
16+
variables:
17+
- name: "API_VERSION"
18+
value: "v1"
19+
- name: "API_URL"
20+
value: "https://api.example.com"
21+
```
22+
23+
## Use variables in content
24+
25+
Reference variables throughout your MDX content using double angle brackets:
26+
27+
### In Markdown
28+
29+
````mdx use-api.mdx
30+
Use the latest version of the API: <<API_VERSION>>
31+
32+
```bash
33+
curl -X GET <<API_URL>>/api/<<API_VERSION>>/users
34+
```
35+
````
36+
37+
### In API references
38+
39+
```yaml openapi.yml
40+
paths:
41+
/users:
42+
get:
43+
description: |
44+
The API version is <<API_VERSION>>
45+
responses:
46+
'200':
47+
description: "Success"
48+
content:
49+
application/json:
50+
schema:
51+
```
52+
53+
### In docs.yml configuration
54+
55+
You can also use variables in your `docs.yml` configuration.
56+
57+
```yaml docs.yml
58+
variables:
59+
- name: "ADMIN_ROLE_NAME"
60+
value: "admin"
61+
```
62+
63+
```yaml docs.yml
64+
roles:
65+
- everyone
66+
- <<ADMIN_ROLE_NAME>>
67+
68+
navigation:
69+
- tab: Admin
70+
layout:
71+
- page: Admin Dashboard
72+
path: pages/admin-dashboard.mdx
73+
viewers:
74+
- <<ADMIN_ROLE_NAME>>
75+
```
76+
77+
<Note>
78+
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.
79+
</Note>

0 commit comments

Comments
 (0)