Sontag language specification
Introduction
This is an informal specification for version 0.1 of the Sontag language, last updated Jul 8, 2024. Sontag is a template language for JavaScript static site generators that borrows concepts from Twig, Liquid, Jinja, and Nunjucks.
Basic concepts
Expressions are enclosed by {{ … }}
. The result of an expression gets interpolated into the surrounding text.
Tags enclosed by {% … %}
provide structure and composition to templates. Some are single tags expressed as {% mytag %}
, others are paired, such as {% mytag %} some content {% endmytag %}
. Some tags support both styles.
Endtags can contain arbitrary text after the tag name.
The language comes with some built-in tags.
Comments marked with {# … #}
are used for documentation and won’t be included in the output.
Built-in tags
set
Assign the result of an expression to an identifier.
Can be used as a single tag:
{% set <identifier> = <expression> %}
Or as a paired tag, in which case the tag’s content gets assigned to the identifier:
{% set <identifier> %}
Content
{% endset %}
if
for
extend
block
include
raw
Process the tag’s content literally, as if it were plain text:
{% raw %}
<p>The syntax for expressions is <code>{{ expression }}</code></p>.
{% endraw %}
Aliased to verbatim
for compatibility with Twig.
Built-in filters
Note: Lots of filters can be readily expressed in JavaScript, but we may want to add some for compatibility with other languages.