Variables
Shared values, written once in variables.yaml.
Variables
Section titled “Variables”A variable is a short value used in many places: a product name, a base URL, a current version.
Defining them
Section titled “Defining them”variables.yaml, beside your pages:
product_name: Stalelessapi_url: https://api.staleless.comcurrent_version: "2.5"Using them
Section titled “Using them”Double braces, anywhere in a page or a snippet:
Call `{{api_url}}/v1/pages` to list every published page.A variable that is not defined fails the undefined-variable rule. A page cannot
be committed with a brace expression that would reach a reader unresolved.
Where they are resolved
Section titled “Where they are resolved”Variables are resolved at build time, so:
- the published page contains the value, not the expression;
- search indexes the value, so a reader searching for your API host finds the page;
- the content API returns the value, because the caller is rendering the page in their own product and has no variable table;
- Ask answers from the value.
Quoting numbers
Section titled “Quoting numbers”YAML reads 2.5 as a number and 2.50 as 2.5. Quote a version:
current_version: "2.50"What a variable is not
Section titled “What a variable is not”A variable is a scalar. It cannot hold a block, a list or conditional content. For a block, use a snippet.
Note
Changing a variable changes every page that uses it. The writer previews which pages are affected before you commit.