You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
0 commit comments