Skip to content

Cheat Sheet

A one-page quick reference for kBars template syntax. Each row links to the full page for details, edge cases, and worked examples — this page is deliberately terse.

Delimiters

Form Effect
{{ expr }} Interpolate, HTML-escaped
{{{ expr }}} Interpolate, unescaped
{{! comment }} Comment, no output
{{{{raw}}}}…{{{{/raw}}}} Body passed through unparsed
\{{ … }} Literal {{ (escapes the tag)

See Template Basics.

Whitespace trimming

Form Effect
{{~ expr }} Trim whitespace before the tag
{{ expr ~}} Trim whitespace after the tag
{{~ expr ~}} Trim both sides
(any tag, alone on its line) Standalone-line stripping, even with no ~

Works on every tag family: interpolation, blocks, else/else if, partials, {{= }}, comments. See Template Basics.

Identifiers

Form Resolves to
this, . Entire current context
this.foo, this/foo, ./foo foo on the current context
../foo, ../../foo foo one/two frames up the context stack
/foo/bar RFC 6901 JSON Pointer
#/foo/bar RFC 6901 URI fragment (percent-decoded)
foo.bar Dot notation
@env/name, @env.name Environment property
@local/name, @local.name Scoped variable ({{= }})
@index, @key, ../@index Current (or ancestor) loop position

An unresolved identifier renders as literal "null". See Interpolation.

Literals

Kind Form
String "…" or '…' — escapes \\ \" \' \n \r \t \uXXXX
Number -?[0-9]+(\.[0-9]+)? — no scientific notation in source
Boolean / null true, false, null

Expressions

{{ a == b }}
{{ a != b }}
{{ a < b }}    {{ a <= b }}    {{ a > b }}    {{ a >= b }}
{{ a and b }}  {{ a or b }}
{{ a and (b or c) }}    {{! parentheses to combine more than one operator }}

Whitespace is required around every binary operator. Only one operator per expression unless grouped with parentheses. See Expressions.

Truthy: everything except null, numeric 0, false, "", and an empty list — note an empty struct {} is truthy. See Truthiness.

Blocks

{{#if a}}…{{else if b}}…{{else}}…{{/if}}
{{#unless a}}…{{else}}…{{/unless}}
{{#each items}}{{ this }} #{{ @index }}{{else}}empty{{/each}}
{{#with obj}}…{{/with}}

{{#each}} pushes @index for a list, @key for a struct (insertion order). See Blocks.

Partials

{{> key }}                       {{! static key, renders against current context }}
{{> key ctx }}                   {{! with a context argument }}
{{> (expr) }}                    {{! dynamic key }}
{{#inline name}}…{{/inline}}     {{! block-scoped inline definition }}
{{#> key}}fallback{{/>}}         {{! partial block: fallback on resolution miss }}

See Partials.

Scoped variables

{{= @env/name = expr }}      {{! render-global, survives block boundaries }}
{{= @local/name = expr }}    {{! frame-scoped, dropped when the block ends }}

See Scoped Variables.

Transforms

{{ expr | transform }}
{{ expr | transform: arg1 arg2 }}
{{ expr | t1 | t2 }}                    {{! left to right }}
{{ expr | t: (other | upcase) }}        {{! parenthesized expression as an argument }}
{{ value | default: "fallback" }}       {{! null / "" / [] → fallback; 0 and false pass through }}

The pipe is lowest precedence — {{ a == b | upcase }} transforms the comparison's result. 56 built-ins ship by default; an application may add, remove, or override them. Full catalog and normative definitions: spec Transforms reference.

String (coerce input to string): upcase downcase append: prepend: contains: remove: remove_first: remove_last: replace: replace_first: replace_last: lstrip rstrip strip strip_html strip_newlines escape escape_once slice: split: truncate: url_decode url_encode url_escape url_param_escape — see String Transforms.

Math (numeric input, collapses whole numbers): abs ceil floor round: plus: minus: times: divided_by: modulo: at_least: at_most:plus/minus/at_least/at_most also accept a date-time input — see Math Transforms.

List (list input; first/last/size also accept strings): compact concat: first last size join: reverse sort: sum: uniq map: where: reject: find: find_index: has: — see List Transforms.

Date/time: as_date_time: parse_date_time: format_date_time: — see Date/Time Transforms.

Environment properties

{{ @env/now }}                              {{! default property: render-start instant }}
{{ @env/now | format_date_time: "yyyy-MM-dd" }}

Render-global, application-configured beyond the built-in now. See Environment Properties.

Number rendering

{{ n }} uses the shortest round-trip decimal form (ECMA-262 Number.prototype.toString() rule); 2 and 2.0 render identically. See Number Rendering.

Escaping quick check

Value interpolated Escaped by {{ }}?
String scalar Yes
Number, boolean, date-time No metacharacters to escape
Struct or list dumped whole No — drill into fields instead

See Security and Escaping Notes.

Where to next