Skip to content

Variables

Shared values, written once in variables.yaml.

A variable is a short value used in many places: a product name, a base URL, a current version.

variables.yaml, beside your pages:

product_name: Staleless
api_url: https://api.staleless.com
current_version: "2.5"

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.

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.

YAML reads 2.5 as a number and 2.50 as 2.5. Quote a version:

current_version: "2.50"

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.