Each template language
In your terminal ssqch docs "Each template language"
Jinja and Nunjucks
Jinja is ssqch's default template language: .jinja (and .j2) pages and layouts render with ssqch's own fork of Nunjucks, the library Eleventy's Nunjucks templates run on, with Jinja's filters, tests, functions and string, list and dict methods on top, so templates written for Jinja (MkDocs themes, say) run too. Markdown and HTML files run through it first. ssqch init starts a site in it. .njk files render with the same library, printing values as Nunjucks does. Add "njk" (Nunjucks) or "j2" to templateFormats for those extensions, markdownEngine: "njk" to run Markdown through the Nunjucks flavor, and render: [njk, md] to do that for one post. A home page, src/index.jinja, that lists the posts:
---
layout: base.jinja
title: Squatch Snacks
---
{% for post in collections.posts %}
<h2><a href="{{ post.url }}">{{ post.data.title }}</a></h2>
<p>{{ post.date | dateformat("%B %-d, %Y") }}</p>
{% endfor %}
- Data: front matter, the cascade,
page,collectionsandcontentin layouts, the same as in the other engines. Undefined values, and properties of undefined values, print nothing (strict: truemakes printing one an error). - Escaping: output is HTML-escaped, as in Nunjucks and Jinja; use
| safeto opt out. A layout'scontentis already marked safe, so{{ content }}works, and so is what a config filter returns withsafe(html).jinja: { autoescape: false }prints.jinjavalues as they are, as MkDocs' Jinja does (fromMkdocs({ templates: true })does that too);| estill escapes. - Filters and functions: Jinja's built-in filters, plus Nunjucks' own (
dump,truncate,forceescape,nl2br,urlize,wordcount,center,random), andpluralize,filesizeformat,striptags,cycler()andjoiner(). Your configfilterswork both ways:{{ title | shout }}and{{ shout(title) }}. On a page whose data has a field with a function's name, the call finds the field first, so use the filter form there. An async function is awaited. - JavaScript properties and methods: Nunjucks templates use JavaScript's, and they work in
.njkand.jinjafiles alike..lengthcounts a list's items or a string's characters ({{ collections.posts.length }}, the same as| length);loop.lengthand an object's ownlengthkey keep their meaning, and on any other object.lengthis undefined, as in JavaScript. Strings and lists also havestartsWith(),endsWith(),includes(),indexOf(),toLowerCase(),toUpperCase()andtrim(), beside Python's (startswith(),lower()). - Dates:
{{ page.date | dateformat }}printsMar 14 2026.dateformat,timeformatanddatetimeformattake"short","medium","long","full","iso","unix", or astrftimepattern (dateformat("%B %-d, %Y")), in UTC. Dates also have Python'sstrftime()andisoformat()and JavaScript'stoISOString()and friends, andnow()is the build's time. - Your own tags: a config filter is a tag too, in
.njkand.jinjafiles alike.{% image "/a.png", "A pine" %}prints whatimage("/a.png", "A pine")returns, without escaping it. With a closing tag, the function gets what's between them first:{% callout "tip" %}...{% endcallout %}callscallout(content, "tip"). That covers the built-in filters as well, so{% markdown %}...{% endmarkdown %}renders Markdown inside a template. - Includes and inheritance:
{% include %},{% extends %}with{% block %},{% import %}and{% from ... import %}read from_includes. Front-matterlayoutworks too. Jinja'sselfrenders a block by name anywhere in the template, as the page's templates have it (the child's over the parent's):<title>{% block title %}Camp{% endblock %}</title> ... <h1>{{ self.title() }}</h1>; a block nothing defines is undefined, and a variable namedselfis that variable. - Nunjucks syntax:
{% elseif %},===,{ title: x },{% for key, value in object %}and Nunjucks' own filters work in.jinjafiles as in.njk. Not supported: extensions that parse a tag's arguments themselves. - Two flavors:
.njkprints values as Nunjucks does, as a site from Eleventy expects (true, a list asa,b, an object as[object Object],noneas nothing, anddumpas compact JSON, escaped unless it's followed by| safe;dump(2)indents it)..jinjaand.j2print as Jinja does (True,['a', 'b'], a spaced, unescapeddump, andtojsonwith a dict's keys sorted, as Jinja'sjson.dumps(sort_keys=True)writes them). A date prints as ISO 8601 in both, whatever the machine's time zone. - The final newline: a
.jinjaor.j2template (a page, a layout, an include, an import) loses one newline at its end, as Jinja's do (keep_trailing_newline=False), so{% include "nav.jinja" %}adds no blank line after the nav, and a page ends where its last tag does..njkkeeps it, as Nunjucks does. Templates written for Jinja (a MkDocs theme) print the same whitespace as they did there. - A key with a method's name: a dict's
items,keys,values,getandupdateare its methods where it has no key of that name, as in Jinja, whosex["items"]falls back to the method too. So{% if link.items %}is true for every dict: a nav entry without children included (VitePress's nav and sidebar useitems). Ask for the key:{% if link.get("items") %}or{% if "items" in link %}. Where the key is there,link.itemsis its value, andlink.items()is still the method. - Strings:
"\u003ch1","\x3c"and"\U0001F332"are the characters they name in both flavors, as in Python and JavaScript, and\n,\t,\r,\\,\"and\'work as usual.insearches a safe string's text ({% if "<h1" not in page.content %}), as Jinja searches itsMarkup. - Where Nunjucks isn't Jinja: a variable set inside a loop or an
ifkeeps its value after it ({% set total = 0 %}{% for x in xs %}{% set total = total + x %}{% endfor %}ends with the sum;namespace()still works), and a variable set in an include stays in the include, so set it in the page, or have the include print it.{% break %},{% continue %},{% with %},{% autoescape %},{% for x in xs if x.ok %}andrecursiveloops are errors that name their line and say what to write instead (an{% if %}inside the loop,xs | selectattr("ok"), a macro that calls itself).loop.previtem,loop.nextitemandloop.depthare undefined. Numbers have no separate float type ({{ 4 / 2 }}prints2), and+and*are JavaScript's: join lists withxs | chain(ys). - Errors name the template and line:
broken.njk:2: syntax error. An error in a layout (a template that another{% extends %}) or after an{% include %}names that template's own line, not the page's{% block %}or the include's.
A Jinja layout, worked through
The rows above, in one site: a base layout with blocks, a layout for posts that fills one in, a Jinja page and a Markdown page, and what each prints.
_includes/base.jinja names its blocks, and prints the title block a second time with self:
<!doctype html>
<html lang="en">
<head>
<title>{% block title %}Cedar Ridge{% endblock %} | Ranger Station</title>
</head>
<body>
{% include "nav.jinja" %}
<main>
<h1>{{ self.title() }}</h1>
{% block body %}{{ content }}{% endblock %}
</main>
</body>
</html>
_includes/post.jinja is a layout for Markdown posts: it extends the base and fills in only the title, so the post's body arrives through the base's {{ content }}:
{% extends "base.jinja" %}
{% block title %}{{ title }}{% endblock %}
A post (posts/cones.md, with layout: post.jinja and title: Pine cone season) gets <title>Pine cone season | Ranger Station</title> and <h1>Pine cone season</h1>: self.title() renders the child's block, not the base's Cedar Ridge. A Jinja page can extend the base itself and fill both blocks, with no layout at all:
{% extends "base.jinja" %}
{% block title %}The Cedar Trail{% endblock %}
{% block body %}
<p>{{ note }}</p>
{% endblock %}
- The include adds no blank line.
nav.jinjaends with a newline, and a.jinjatemplate loses one at its end, so<nav>...</nav>is followed straight by<main>. The page itself ends at</html>, with no newline after it. In.njkboth newlines stay. - Values are escaped. With
note: "Pine cones <em>everywhere</em> & a stump"in the page's data,{{ note }}printsPine cones <em>everywhere</em> & a stump, and{{ note | safe }}prints the<em>. Withjinja: { autoescape: false }in the config,{{ note }}prints it as it is, and{{ note | e }}is the escaped one: the choice for a theme written for MkDocs, where nothing is escaped unless it asks. - Wrong on purpose: a block name that's misspelled in the child (
{% block titel %}) isn't an error, as in Jinja: the base's ownCedar Ridgeprints.strict: truedoesn't catch it either, since nothing undefined printed, so a page whose title is the default's is the sign to look for.
Edge
Edge.js templates (.edge) render with edge.js itself (6.5), so what its documentation describes works. Add "edge" to templateFormats, and markdownEngine: "edge" to run Markdown through it (ssqch init --engine edge does both). Its components with slots are handy in Markdown: component-docs uses them in place of MDX.
export default defineConfig({
templateFormats: ["edge", "md"],
markdownEngine: "edge",
});
All of edge.js is there: {{ }}, {{{ }}}, {{-- --}}, @{{ }}, @if/@elseif/@else/@unless, @each (with index, objects, @else and $loop: index, total, isFirst and isLast (or first and last), isOdd and isEven), @let (destructuring included) and @assign, @include and @includeIf, @component and @!component with named slots and isolated scope, @eval, @inject, @stack and @pushTo, ~ whitespace control, and edge.js's helpers (excerpt, html.attrs, nl2br and the rest; nl2br gives HTML to print as it is, so escape what it's given: {{{ nl2br(html.escape(text)) }}}). Expressions are JavaScript: object and array literals, template literals, optional chaining, arrow functions with block bodies, regular expressions, the in operator, await, and Node's globals (process, URL; a page's value or a config function of the same name wins). await waits for a promise, and an async function (an async config filter) is awaited when it's called in a mustache or @let. Inside a callback it's awaited in map (posts.map(p => cover(p))), and in filter, find and the others it's an error that says to call it first with @let.
ssqch smooths a few of edge.js's corners: an undefined value prints nothing (edge.js prints undefined), a call reaches the config filter when the page has a field of the same name ({{ image(...) }} beside image: in front matter), a mustache can start with an object literal ({{ { tip: 'T' }[kind] }}), @let(n = n - 1) reads the value it replaces, reverse() and sort() give copies (so a page can't reorder a collection under the next one), dates are in UTC and print as ISO 8601, strings index by character, and numbers never print in exponent notation. {{ safe(html) }} prints html as it is, as edge.js's html.safe does. A variable an include declares with @let stays in the include unless the including template declares it first. Errors report template:line through the include and component chain, a parse error is in edge.js's words (parse error in page.edge: line 2: Unexpected token), and a function that isn't there says which one you probably meant (index.edge:2: `uper` is not a function (did you mean `upper`?)), or ssqch's name for another generator's (slug).
Liquid
Coming from Jekyll or a Shopify theme? Add "liquid" to templateFormats and .liquid pages and layouts render with liquidjs (10.30), the Liquid library Eleventy uses. Use markdownEngine: "liquid" to run Markdown through Liquid instead of Jinja, or render: [liquid, md] for one post.
import { defineConfig } from "ssqch";
export default defineConfig({
templateFormats: ["liquid", "md"],
markdownEngine: "liquid",
filters: { shout: (s) => s.toUpperCase() },
});
- Data: Liquid templates get the same data as the other engines: front matter, the cascade,
page,collectionsandcontentin layouts. Unknown variables and properties print nothing, as in Jekyll. Front matter is at the top level ({{ title }}), not underpageas in Jekyll: a template that readspage.titlegets nothing, and the build warns once for each such name, naming the page. - Filters: liquidjs' standard filters and tags (
where_exp,sum,{% liquid %},{% echo %}), Jekyll'spush,pop,shift,unshift,array_to_sentence_string,date_to_xmlschema,date_to_rfc822,date_to_stringanddate_to_long_string, and Shopify'spluralize.slugifyis ssqch's, the same as in the other languages. Your configfilterswork too:{{ title | shout }}callsshout(title), and{{ x | wrap: "[", "]" }}callswrap(x, "[", "]"). A config filter replaces a built-in one with the same name. - Dates print as
2026-01-02 00:00:00 +0000, in UTC, whatever the machine's time zone, in every filter, anddatereads ISO 8601 text (2024-03-04). - Objects:
{{ some_object }}prints[object Object], so write{{ some_object | json }};{{ some_object.size }}is its number of keys, and a string'ssizecounts as JavaScript does (caféis 4). A variable namedemptyorblankis Liquid's keyword ({% if empty %}), so rename it. - Includes:
{% include "nav.html" %}and Jekyll's{% include nav.html section="home" %}(read asinclude.section) see the page's variables.{% render "footer", year: 2026 %}sees only what it's given, and prints nothing for a variable it wasn't given (withstrict, that is an error). Both read from_includes, adding.liquidwhen the name has none. include_relative: Jekyll's{% include_relative parts/intro.md who="rangers" %}reads a file beside the template that has the tag (or in a folder below it), not in_includes, and renders it with the page's variables andinclude.who. The name can have{{ }}in it (parts/{{ lang }}.md);..is refused, as in Jekyll. The file is read as it is, front matter and all, and a Markdown file there is a page of its own too, so give itpermalink: falsein directory data (not in its front matter) or keep it out withignore.- Your own tags: a config filter is a tag too, as in Nunjucks, so a Jekyll plugin's tag can be a function:
{% seo %}prints whatseo()returns, without escaping it. Arguments are values, by commas or spaces ({% image "/a.png", "A pine" %}), andname: valueor Jekyll'sname=valuearrive as one object at the end ({% seo title=false %}callsseo({ title: false })). With a closing tag, the function gets what's between them first:{% callout "tip" %}...{% endcallout %}callscallout(content, "tip"). A function can be async. Liquid's own tags keep their names: a filter calledincludeis a filter only. Arguments are plain values: a filter inside a tag's arguments ({% image page.cover | url %}) is an error, soassignit first. - Ruby's Liquid: math,
splitand blank blocks follow Ruby's Liquid (4.0.4, Jekyll's and GitHub Pages'):plus,minus,times,divided_by,moduloand the rest read text as Ruby does ("3.5"is a float,"3.5x"is 3,"r>"and nothing are 0);splitdrops empty strings at the end and splits" "at every run of whitespace; and anif,unless,fororcasewhose bodies are only whitespace,assign,captureand comments writes nothing, so a layout that computes in blocks doesn't fill with blank lines. Dividing by zero is still an error. - Mixing engines: a Liquid page can use a Jinja layout and the other way around.
- Errors name the file and line, and an unknown filter gets the closest name (
did you mean).
Handlebars and Mustache
Add "hbs" (or "handlebars") or "mustache" to templateFormats, and those files render with handlebars.js (4.7). Mustache templates render as Handlebars.
- Data: the same as the other engines, so a template reads the page's real data and collections, and a missing value prints nothing. A date passed to a helper itself (
{{year date}}) arrives as ISO 8601 text, and one inside an object the helper is given ({{byline post}}) is aDate. - Escaping:
{{ }}escapes HTML and{{{ }}}doesn't, so a layout writes{{{content}}}. - Helpers: Handlebars' built-ins (
if,unless,each,with,lookup,len,eqand the other comparisons). Your configfiltersare helpers:{{shout title}},{{wrap title "[" "]"}}, and hash arguments (size=2) arrive as a trailing object. An unknown helper gets the closest name (did you mean). Use{{len list}}, notlist.length. - Partials: every file in
_includes, by its path with or without the extension:{{> nav}}or{{> nav.hbs}}. A name without an extension is the Handlebars file when there is one. - Mustache: variables,
{{{ }}}, partials, sections over lists and truthy values ({{#items}}{{.}}{{/items}}) and inverted sections ({{^items}}none{{/items}}), also in.hbsfiles. Inside a section, reach outer values with../name, as in Handlebars. Not supported: lambdas and changing delimiters. - Errors name the file and line, and an error in a partial names the partial's file.
EJS
EJS templates (.ejs) are plain JavaScript between tags, rendered with ejs 3.1, which is bundled in ssqch (no npm install). Add "ejs" to templateFormats, and markdownEngine: "ejs" to run Markdown through it. The output matches EJS 3's, whitespace included.
<ul>
<%_ for (const post of collections.posts) { _%>
<li><a href="<%= post.url %>"><%= post.data.title %></a></li>
<%_ } _%>
</ul>
- Tags:
<% code %>,<%= escaped %>,<%- raw %>(a layout writes<%- content %>),<%# comment %>and<%%for a literal<%.-%>drops the newline after a tag, and<%_/_%>the spaces and tabs around it too. - Data: the page's data, as variables (
title,page,collections, andlocalsfor all of it). Your configfiltersand ssqch's functions (markdown,highlight,navTree, ...) are functions by the same names:<%= shout(title) %>. A config filter is called directly, without converting anything. - Async: a function's promise that's printed (
<%= later(x) %>) is awaited, and a template canawait. - Dates print at UTC (
Sun Apr 05 2026 06:07:08 GMT+0000), in<%= %>,<%- %>and lists, whatever the machine's time zone. Format a date in the template to show it otherwise (date.toLocaleString("en-US", { timeZone: "America/New_York" })). - Includes:
<%- include("partials/nav") %>reads_includes/partials/nav.ejs(and the themes'),include("./card")reads from the template's own folder, and a second argument adds variables:include("card", { post }). One that isn't there says which file you probably meant. - Errors name the template and line, and the lines under them are the file's own. A variable nothing defines is a
ReferenceError, as in EJS (typeof xis still safe). - Starters:
ssqch init --engine ejs(and--starter docs --engine ejs) writes the starters' layouts, render hook and containers in EJS.