Writing Templates¶
A kBars template is text with tags in it — {{ name }}, {{#if …}}, {{> partial }}, and so on —
that get replaced or expanded when the template is rendered against a context: a JSON- or
YAML-shaped bag of data (an object with named fields, possibly nested, possibly containing lists).
Rendered against a context where name is "Alice", this produces:
kBars mixes syntax you may already know from Mustache, Handlebars, and Liquid — see Coming from Handlebars, Mustache, or Liquid if one of those is familiar. Otherwise, start with Template Basics and work through the pages below in order; each builds on the last.
Where to next¶
- Cheat Sheet — a one-page syntax reference, once you already know the language and just need a quick lookup.
- Coming from Handlebars, Mustache, or Liquid — a fast map from what you already know to what kBars calls it.
- Template Basics — text, delimiters, comments, raw blocks, whitespace trimming.
- Interpolation — how
{{ identifier }}resolves against the context. - Expressions — literals, binary operators, and truthiness.
- Blocks —
{{#if}},{{#unless}},{{#each}},{{#with}}. - Transforms — the
|pipeline for reshaping a value before it's interpolated. - Partials —
{{> key }}, reusing one template from inside another. - Environment Properties and Scoped Variables — reading and binding values outside the current context.
- Security and Escaping Notes — what
{{ }}HTML-escapes for you, and what it doesn't. - Number Rendering — how numeric values render as text.