Variables

Project Variables help you label parts of your documentation that are repetitive, to be able to change them centrally in one place. It also allows you to personalise the documentation for your readers.

For example, you might want all of API reference to use the latest version in their example requests. Without variables, you would need to upload a new reference containing changes to each example request every time you update the version.

One of the example requests might look as such:

Javascript
Copy

With variables, you'll be able to centrally change version value, saving you time and effort.

How to use Project Variables?

There are two things needed to get project variables setup:

  • Add a JSON object of the variables that will be available in the documentation.
  • Insert variable references in the documentation by wrapping it in percent signs as such %variable%.

Where can you use Project Variables?

Project variables can be inserted in:

  • Page content and blocks.
  • API Reference descriptions.
  • Index external links.
  • Custom javascript.
  • Default landing page layout.
  • Custom HTML in landing pages.

Editing Project Variables

To edit project variables, do the following:

  • From the sidebar, select Project Settings
  • Under Project Variables, click on the button on the right.
  • Enter a JSON object defining all your variables. For example:
Javascript
Copy

Using Project Variables in References

To use project variables in an API Reference, replace all occurrences of the variable with the variable reference. For example, one definition property could be:

YAML
Copy

Or to replace a variable named subdomain in the Server URL:

YAML
Copy

Note that YAML requires you to use double quotations to escape a string containing percent sign.

Using Project Variables in Scripts

To use project variables in scripts, you must first set up the project to expose variables through window.vars object. To do that:

  • From the sidebar, select Project Settings
  • Under Project Variables, click on the button on the right.
  • Check Expose Variables in Javascript.
  • Click Save.

For the published docs, once the project loads, you'll be able to access the variables (defined under Project and injected through personalisation) through window.vars.

Personalising Docs

You can use variables to personalise docs. Read more about it in Personalised Docs.

Known Limitations

  • Variables do not work as HREFs for links.
Type to search, ESC to discard
Type to search, ESC to discard
Type to search, ESC to discard
  Last updated