본문으로 건너뛰기

Variables & Substitutions

vars is a special keyword that lets you define variables. These variables can be referenced with the substitution syntax: ${}.

Cat-1Cat-2

Variables can be nested

Use . to refer to nested variables.

button

Variables are scoped

They work just like variable scopes in programming. Substitutions can refer to variables defined in a more outer scope, but not a more inner scope. If a variable appears in two scopes, the one closer to the substitution is used.

Global load balancerzone1us-east-1 API

Single quotes bypass substitutions

ab Send field ${names}

Spread substitutions

If x is a map or an array, ...${x} will spread the contents of x into either a map or an array.

dataaintPK, NOT NULL, UNQDRAFT DISCLAIMERI am not a lawyer

Configuration variables

Some configurations can be made directly in vars instead of using flags or environment variables.

This is equivalent to calling the following with no vars:

xy
Precedence

Flags and environment variables take precedence.

In other words, if you call D2_PAD=2 d2 --theme=1 input.d2, it doesn't matter what theme-id and pad are set to in input.d2's d2-config; it will use the options from the command.

data

data is an anything-goes map of key-value pairs. This is used in contexts where third-party software read configuration, such as when D2 is used as a library, or D2 is run with an external plugin.

For example,