Typed Templates and Expressions
Use typed inputs, calculations, local bindings, conditions, and collection iteration in any SevenMark document. These constructs produce the same native content nodes as ordinary markup.
{{{#let attack = 120}}}
{{{#let damage = round(attack * 1.25, 1)}}}
Damage: {{{#expr damage}}}Pure calculations do not require host data. Live display macros keep descriptors for the frontend to fill. Context functions use the host-approved evaluation context described in the renderer API.
Values and inputs
Values include String, Bool, Integer, Decimal, Null, List, Record, Reference, Date, Instant, and structured Content. Declare a template input with #param:
{{{#param title: String = "Item"}}}
{{{#param attack: Decimal = 0.0}}}
{{{#param featured: Bool = false}}}
{{{#param note: String? = null}}}
{{{#expr title}}}: {{{#expr attack}}}- An omitted input uses its default. An input without a default is required.
- An explicit empty String,
0, andfalseretain their values. - A type followed by
?also accepts Null.value ?? fallbackreplaces Null; it does not replace an empty string or zero. - Input names must be declared. Unknown inputs and duplicate declarations are errors. Declare inputs at document level.
provided("title")reports whether the caller supplied the input, even when its value is empty. It does not test whether a default exists.
Current include arguments cross a text boundary. The declared type controls conversion: numeric types parse numeric text, Bool accepts true or false, Date accepts YYYY-MM-DD, and Instant accepts RFC 3339. List and Record inputs accept JSON. A Reference input parses a canonical document address. For a nullable input, the text null supplies Null. Conversion failures are errors.
List and Record defaults can use native expression literals. Structured Content can be produced by built-ins such as map; passing arbitrary markup as a typed Content input is not implemented. A String never becomes markup automatically.
Bindings and output
#let defines an immutable local. Its value becomes visible after the declaration. #expr emits a scalar as text or emits structured Content.
{{{#let title = "[[This remains text]]"}}}
**{{{#expr title}}}**This displays the bracket characters inside bold text; it does not create a wiki link. Use ordinary link syntax for a link. Lists and Records require explicit selection, iteration, or formatting rather than implicit text conversion.
Expressions
Expressions use bare names, function calls, literals, and these operators. The table lists precedence from highest to lowest.
| Operators | Meaning |
|---|---|
value[index], value.field | Collection access; List indexes start at zero |
!, unary - | Bool negation and numeric negation |
*, /, % | Multiplication, division, remainder |
+, - | Numeric addition and subtraction |
==, !=, <, <=, >, >= | Equality and ordering |
&& | Short-circuit Bool AND |
|| | Short-circuit Bool OR |
?? | Use the right value when the left value is Null |
condition ? selected : alternative | Evaluate the selected value only |
Use parentheses to group expressions. Coalescing and conditional selection are right-associative. Arithmetic is left-associative. Write two comparisons with a logical operator; chained comparisons such as 1 < score < 10 are errors.
Strings use double quotes with JSON escapes, including \", \\, \n, \r, \t, and \uXXXX. String literals contain text, including text that resembles SevenMark delimiters.
{{{#let values = [1, 2, 3]}}}
{{{#let item = {name: "Sword", attack: 120, note: null}}}}
{{{#expr item.name}}}
{{{#expr values[0] + item["attack"]}}}
{{{#expr item.note ?? "No note"}}}Conditions require Bool. Strings and numbers do not become Bool implicitly. Equality does not convert numeric text: "5" == 5 is false. Integer and Decimal values compare within one numeric family. Ordering accepts two numbers, two strings, two Dates, or two Instants. Unsupported operand types are errors.
Numbers and rounding
Integer is a checked signed 64-bit integer. Decimal uses a 96-bit coefficient and a scale from 0 through 28. Its range and available fractional precision depend on the coefficient. It is not an arbitrary-precision number.
Integer addition, subtraction, multiplication, and remainder retain Integer when both operands are Integer. / produces Decimal division. Decimal arithmetic uses the bounded decimal backend; results can round to its available precision. Overflow and division by zero are errors.
round(number, digits) accepts 0 through 28 fractional digits. Its midpoint rule is away from zero: round(1.25, 1) is 1.3, and round(-1.25, 1) is -1.3. The default is zero digits. Use int, decimal, bool, and str for explicit conversions. int requires an integral number or integer text; it does not silently truncate a fraction or replace invalid input with zero.
+ performs numeric addition. Use concat or join for text. Numeric evaluation does not depend on a reader's locale. TeX remains a display format.
Conditions and scopes
{{{#let score = 85}}}
{{{#if score >= 60 ::
{{{#let label = "Passed"}}}
**{{{#expr label}}}**
}}}
{{{#else :: Needs another attempt. }}}An #else belongs to the preceding #if. Only whitespace may appear between them. Each selected branch has a child scope. A branch can shadow an outer binding, but its declarations do not escape. Rebinding a name in the same scope is an error. Only the selected branch executes. Editor diagnostics inspect names and function calls in all parsed branches without querying site data.
Use #let for locals and #param for template inputs. See conditionals for more examples.
Iteration and structural content
Iterate a List in item order. Iterating a Record yields Records with key and value fields, in field order. Each iteration has a child scope.
{{{#for number in range(1, 4) ::
Number: {{{#expr number}}}
}}}range(start, until, step) excludes until; the default step is 1. A negative step counts down. A zero step is an error. Ranges are finite Lists and their size is checked before allocation.
Inside a table or list, place #for at the structural level it produces:
{{{#let skills = [{name: "Dash", power: 2}, {name: "Guard", power: 0}]}}}
{{{#table
[[ [[Skill]] [[Power]] ]]
{{{#for skill in skills ::
{{{#let power = skill.power * 10}}}
{{{#if power > 0 ::
[[ [[{{{#expr skill.name}}}]] [[{{{#expr power}}}]] ]]
}}}
{{{#else :: [[ [[{{{#expr skill.name}}}]] [[No power]] ]] }}}
}}}
}}}
{{{#list
{{{#for skill in skills ::
[[{{{#expr skill.name}}}]]
}}}
}}}The same form can produce cells inside a table row. Use #let, #if/#else, and nested #for blocks at row, cell, and list-item levels. They use the same lexical scopes and Bool conditions as ordinary content. Each block produces complete rows, cells, or items rather than partial markup delimiters.
Complete template and article
Save this source as the Template named ItemCard. Defaults also make it usable as a standalone preview:
{{{#param title: String = "Item"}}}
{{{#param attack: Decimal = 0.0}}}
{{{#param featured: Bool = false}}}
{{{#param skills: List = [{name: "Dash", power: 2}, {name: "Guard", power: 0}]}}}
{{{#let damage = round(attack * 1.25, 1)}}}
{{{ #style="border:1px solid #888;padding:12px"
**{{{#expr title}}}**
{{{#if featured :: Featured item }}}
{{{#else :: Standard item }}}
Damage: {{{#expr damage}}}
{{{#table
[[ [[Skill]] [[Power]] ]]
{{{#for skill in skills ::
[[ [[{{{#expr skill.name}}}]] [[{{{#expr skill.power}}}]] ]]
}}}
}}}
}}}Use it from an article with named arguments:
# Example equipment
{{{#let attack = 120}}}
{{{#include #namespace="Template" #title="Sword" #attack="{{{#expr attack}}}" #featured="true"
ItemCard
}}}The caller evaluates the argument expression. The template receives the resulting text and converts it according to its declared input type. Caller locals do not become template globals. The host must supply and authorize the selected template revision.
Time and site statistics
Use live macros to display current time or site statistics in cached HTML. The frontend fills and refreshes those widgets after rendering.
Use the functions below when a calculation or condition needs a fixed snapshot. They read approved context supplied by the host. All now() calls in one render use the same instant. today() and yesterday() use the site's IANA time zone to define calendar boundaries. This time zone does not control viewer displays.
{{{#let total = site.document_count("document")}}}
{{{#if total >= 100 :: The approved snapshot contains at least 100 documents. }}}
Snapshot time: {{{#expr format_date(now(), "%Y-%m-%d %H:%M")}}}Yesterday is the previous calendar day from local midnight inclusive to today's local midnight exclusive. It is not necessarily 24 hours. An explicit interval can use Date or Instant endpoints:
{{{#expr site.documents_created(date("2026-10-01"), date("2026-11-01"), "document")}}}
{{{#expr site.active_user_count(add_days(today(), -30), today())}}}The second example requests the 30 calendar days before today. The host defines the public counting policy and supplies the matching aggregate. Missing, unsupported, failed, and expired facts do not become zero. Used facts carry version, observation time, and expiry metadata for cache validation. SevenMark does not query a database or fetch documents to calculate site statistics.
Calendar intervals use the earliest occurrence of an ambiguous local midnight. A midnight that does not exist in the selected time zone is an error; use explicit Instant endpoints when that historical boundary needs a different policy.
These results form part of the cached HTML. The host must validate fact versions and expiry and invalidate clock-dependent results before reuse. Live display macros retain descriptors instead; their updates cannot affect server-evaluated conditions, included revisions, or references. See macros.
Maps
map produces structured map content. Latitude must be between -90 and 90; longitude must be between -180 and 180. Zoom is an Integer from 0 through 19, with a default of 12.
{{{#expr map(37.5665, 126.978, 12, "Seoul", [
{latitude: 37.57, longitude: 126.98, label: "Destination"}
])}}}The browser host can mount a configured interactive map adapter. The document supplies coordinates and labels. It does not supply iframe markup, scripts, API keys, or provider URLs. A location/link fallback remains usable when the adapter is unavailable. Address search and geocoding are not implemented by this function.
Built-in library
Function arguments are positional. Optional arguments in this table show their defaults; they are not named-argument syntax. Completion and hover use the same registry as evaluation.
| Purpose | Functions |
|---|---|
| Conversion | int(value), decimal(value), bool(value), str(value) |
| Presence and size | provided(name), is_null(value), is_empty(value), len(value), byte_len(text) |
| Numbers | round(number, digits = 0), abs(number), min(...), max(...), clamp(number, lower, upper) |
| Text | concat(...), join(list, separator) |
| Collections | range(start, until, step = 1), sum(list), sort(list), keys(record), values(record), get(collection, key, default = null) |
| References | ref(address, namespace = "document") |
| Time | now(), today(), yesterday(), date(text), instant(text), add_days(date, days), days_between(from, until), age(date), dday(date), format_date(value, format) |
| Site facts | site.document_count(namespace?), site.user_count(), site.active_user_count(from, until), site.documents_created(date, namespace?) or site.documents_created(from, until, namespace?) |
| Content | map(latitude, longitude, zoom = 12, label = "", markers = []) |
len counts Unicode grapheme clusters in a String, elements in a List, or fields in a Record. byte_len counts UTF-8 bytes. sort is stable and requires mutually comparable scalar values. format_date accepts checked strftime-style directives; an invalid directive or a field absent from the value is an error.
Errors and recovery
A markup error affects its own display node. SevenMark shows the exact failed syntax as escaped red text and supplies an error diagnostic. Other content keeps rendering. Hover the marked syntax or read the editor diagnostic for the reason. A failed expression cannot supply a parameter value or document address. Bindings created by a failed node do not escape into following content.
An invalid include argument marks the caller's include. An error inside an approved included body marks the source of that body. A failed condition marks its if and adjacent else as one unit. A failed table row, cell or list item keeps the surrounding structure and valid items. Inactive branches do not execute.
Request-envelope errors, missing host approvals or calculation facts, and resource exhaustion remain service errors. They do not become successful partial renders.
Execution limits and current scope
One configurable work budget covers a complete render, including loops, function calls, and included revisions. Bulk operations also charge for the data they process. A nested call cannot reset the budget. The initial work default is 10,000,000 units; it measures evaluator work, not milliseconds. The host exposes its current limits and each operation's accepted usage. A rejected charge can leave positive remaining work. Unknown counters stay unknown. The editor must not add separate preflight requests together as one render's work. Source, parser storage, evaluated expansion, and response bytes have separate limits. Operators can change operational limits. Fixed structural and value policies remain explicit. See the resource API. Dynamic values and output copies consume expansion capacity before allocation.
Use finite collection/range loops and registered built-ins. User-defined functions, modules, general loops, and recursive functions are not implemented. Structured Content argument slots and a general document-existence expression are also not implemented. Ordinary link existence resolution continues to work.
The formatter preserves expressions, grouping, declarations, control flow, and content. It formats the source AST before evaluation. Its default target width is 80 display columns with two-space structural indentation. Expressions and parameter headers break only at legal whitespace boundaries. Quoted values, prose and raw languages retain their content. Headings and code-fence metadata keep their required physical line; these and unbreakable values can exceed the target width. Typed editor support includes lexical diagnostics, completions, function hover, definition navigation, symbols, and folding.