colin.toml, then reference them anywhere via vars.*.
Variables separate configuration from content. Rather than hardcoding values like environment names, dates, or feature flags into your documents, declare them as variables. This makes documents portable across environments and easier to update.
Defining Variables
Add variables to the[vars] section of your colin.toml. Variable names must be unique case-insensitively (e.g., apiKey and apikey cannot both exist).
Simple Syntax
As a shorthand for variables with defaults, assign values directly. Colin infers the type from the value:colin.toml
Typed Syntax
For more control, use subsections with explicit type declarations:colin.toml
| Field | Description | Default |
|---|---|---|
type | Variable type (see below) | string |
default | Default value | None |
optional | If true, returns None when not provided | false |
Supported Types
| Variable Type | Python Type | Example Value |
|---|---|---|
string | str | "production" |
bool | bool | true, false |
int | int | 42 |
float | float | 3.14 |
date | datetime.date | "2024-01-15" |
timestamp | datetime.datetime | "2024-01-15T10:30:00" |
Providing Values
Variables can be set through multiple sources. Colin resolves them in order of precedence:- CLI
--varflags (highest priority) - Environment variables (
COLIN_VAR_<NAME>) colin.tomldefaultsNoneif optional- Error if required and not provided
CLI Overrides
Pass values at runtime with--var:
--var flags can be combined. Values are always strings on the CLI; Colin converts them to the declared type.
Environment Variables
Set variables through the environment using theCOLIN_VAR_ prefix:
api_key reads from COLIN_VAR_API_KEY.
Using Variables
Access variables in any template through thevars namespace:
models/report.md
Working with Types
Date and timestamp variables return Python objects, so you can call their methods directly:Optional Variables
Optional variables returnNone when not provided. Use conditionals to handle missing values:
Template-Side Defaults
For dynamic defaults like the current date, use Jinja expressions directly in your templates:report_date is provided via CLI or environment variable, that value is used; otherwise, the expression after or provides the fallback.
Recompilation
Colin tracks which variables each document uses. When a variable’s value changes on the next compile (via--var or environment), only documents that accessed that variable will recompile.
For example, if doc1.md uses vars.environment and doc2.md uses vars.debug, changing --var environment=staging will only recompile doc1.md.