David Hellyer Sign out Sign in

Template Toolkit variables

Use TT variables and logic in page content and the view template.

Template Toolkit variables

Page content and view templates are processed by Template Toolkit (TT). Variables come from three sources: site-wide configuration, per-page definitions, and automatic page metadata.

Variable sources

Site variables (from lazysite.conf):

site_name: My Site
site_url: ${REQUEST_SCHEME}://${SERVER_NAME}
footer_text: Copyright 2024

Per-page variables (from front matter tt_page_var:):

---
tt_page_var:
  features: scan:/docs/features/*.md sort=title asc
  version: url:https://example.com/version.txt
  label: Custom Label
---

Automatic variables (always available):

Value types

Literal value:

my_var: some text

Environment variable interpolation (allowlisted variables only):

site_url: ${REQUEST_SCHEME}://${SERVER_NAME}

Allowlisted variables: SERVER_NAME, SERVER_PORT, REQUEST_SCHEME, HTTPS, REQUEST_URI, REDIRECT_URL, DOCUMENT_ROOT, SERVER_ADMIN.

Remote URL fetch:

latest: url:https://example.com/data.txt

Directory scan:

posts: scan:/blog/*.md sort=date desc

Example

---
title: Dashboard
tt_page_var:
  posts: scan:/blog/*.md sort=date desc
  motto: Live free or die
---
## [% motto %]

[% FOREACH post IN posts %]
- [[% post.title %]]([% post.url %]) ([% post.date %])
[% END %]

Notes