Templates #
Templates are plain HTML with a small, literal placeholder language. There is no expression language and no inheritance beyond text includes.
| form | meaning |
|---|---|
{{name}} |
value, HTML-escaped |
{{{name}}} |
value, raw HTML |
{{> partial.html}} |
inline a template from the templates directory |
{{#each name}}…{{/each}} |
repeat a block; {{this}} is the current item |
{{#if name}}…{{else}}…{{/if}} |
one branch; true for a non-empty string or list |
Missing values render as an empty string. {{else}} is optional. Includes are
resolved relative to the templates directory; absolute paths, .., and cycles
are errors. A template that references an unknown block is an error naming the
file and line.
Context #
Every page receives site, lang, title, route, base, content,
backlinks, backlink_count, source and tag_links. date is set when the page has one;
tags is a list of strings, and tag_links is a list of {label, href}
maps pointing at the generated tag pages:
{{#each tag_links}}<a href="{{href}}">{{label}}</a>{{/each}}
Front matter keys are exposed flat. content and backlinks are raw HTML;
the rest is escaped.
Every table in data/ is also available by name, and every context hook
key is merged in. A front matter key that collides with a built-in, a data
table or a hook key is an error. title, tags, date, draft and
template are content directives, not extra context.
Data tables #
Each data/<name>.tsv is a table: a header row names the columns, then one
row per line. # lines and blank lines are ignored. Rows become maps:
<ul>
{{#each logs}}<li>{{date}} — {{text}}</li>{{/each}}
</ul>
Inside the loop, {{date}} reads the current row and falls back to the page
context if the column is missing. {{this}} is the current item on a list of
strings, such as tags. A row with more cells than the header is an error;
missing trailing cells are empty.
Generated pages #
Listing and tag pages use the same engine but a smaller context. They also
receive content and backlinks as empty strings.
Collection listing (list.html): title, collection, count and
items. Each item row has title, href (already relative to the listing),
route, date, id, backlinks (the note's incoming count), tags
(comma-joined) and source.
When the collection sets paginate, the same template renders every page.
items holds only the current page's rows and count stays the total. The
extra values are:
| value | meaning |
|---|---|
paginator.current_page |
current page number, starting at 1 |
paginator.total_pages |
number of pages |
paginator.previous_path |
link to the previous page, or empty on page 1 |
paginator.next_path |
link to the next page, or empty on the last page |
paginator.pages |
list of {num, path, current} rows for numbered links |
current is true on the current page and empty otherwise. Page 1 keeps the
collection route; later pages live at <route>page/<n>/. A listing that fits
on one page has no paginator values, so the blocks render nothing:
{{#if paginator.previous_path}}<a href="{{paginator.previous_path}}">← Previous</a>{{/if}}
{{#each paginator.pages}}{{#if current}}<span>{{num}}</span>{{else}}<a href="{{path}}">{{num}}</a>{{/if}}{{/each}}
{{#if paginator.next_path}}<a href="{{paginator.next_path}}">Next →</a>{{/if}}
Tag page (tag.html): tag, slug, count and items, with the same
row shape.
Tag index (tags.html): title (Tags), count and items. Each row
has tag, slug, count, route and href.
Title #
The first H1 in the Markdown body is removed. The template renders the title
with <h1>{{title}}</h1>. Title precedence is front matter title, then the
first H1, then the file stem.
Default template #
page.html includes base.html. The shipped base renders:
<title>{{title}} — {{site}}</title>
<h1>{{title}}</h1>
{{{content}}}
{{{backlinks}}}
Select a different template per page with template: name.html in the front
matter.
Overriding the defaults #
The five templates are embedded in the binary: base.html, page.html,
list.html, tag.html and tags.html. A project templates/ directory
replaces them as a whole: when the directory exists, every template is
read from it and there is no per-file fallback. Copy all five before editing,
or the build fails on a missing include.
uteri eject writes them for you, along with the selected theme's
style.css:
uteri eject
Existing files are never overwritten, so a second run reports
nothing to eject. style.css is skipped when a project stylesheet or
static/style.css already exists, because writing it would change the
published site. Ejecting never builds and never changes the output.
After ejecting, edit templates/*.html and style.css, then run
uteri build. See CONFIG.md for theme and templates.