Variables allow you to store and reuse values throughout your document. They are essential for avoiding repetition, creating dynamic content, and building reusable components.
Use .var {name} {value} to define a variable. The value is a dynamic value, meaning it can be of any type: text, numbers, booleans, or even complex elements like layouts.
.var {name} {Quarkdown}Once defined, you can access a variable by calling it as a parameter-less function:
.var {name} {Quarkdown}
Hello, **.name**!Hello, Quarkdown!
You can update a variable’s value at any point. There are two equivalent ways to do this:
.myvar {newvalue}.var {myvar} {newvalue}.var {mynumber} {5}
.mynumber
.mynumber {.mynumber::sum {1}}
.mynumber5
6
As mentioned in Syntax of a function call:
A body argument always refers to the last parameter of the signature.
This means a variable’s value can span multiple lines and contain complex block content, not just simple inline values. This is powerful for storing reusable layouts, styled containers, or any structured content.
.var {myrow}
.row gap:{2cm}
A
B
C
.container background:{teal} padding:{1cm}
.myrowA
B
C
For temporary variables that should only exist within a limited scope, see the .let function. Unlike .var, which creates document-wide variables, .let creates variables that exist only within a lambda block.