Variables & Substitutions
vars
is a special keyword that lets you define variables. These variables can be
referenced with the substitution syntax: ${}
.
Variables can be nested
Use .
to refer to nested variables.
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.
Single quotes bypass substitutions
Spread substitutions
If x
is a map or an array, ...${x}
will spread the contents of x
into either a map
or an array.
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
:
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,