Overview
SellAuth renders templates with Nunjucks, a Jinja-style template language for JavaScript. It is used in two places:- Storefront themes, in every
.njkfile of a theme. - Custom email templates, which use the same language with a different set of variables and helpers.
Language basics
Output
Conditionals
Loops
loop.index (1-based), loop.index0, loop.first, loop.last, and loop.length. Objects can be iterated as key and value pairs:
Variables
Macros
Macros are reusable markup within a single file. They are file-local, you cannot call a macro defined in another file.Comments
Filters
Filters transform a value with| and can be chained and given arguments:
The dictionary switch
Nunjucks has noswitch. The official themes map a setting value to a class or a token with a dictionary lookup plus a fallback, and it is worth adopting because it keeps components readable:
Escaping
Autoescaping is on. Everything you output with{{ }} is HTML-escaped unless you explicitly mark it safe.
Storefront themes
Rendering components and snippets
Themes compose pages with two SellAuth-specific tags.Component not found or Snippet not found is rendered in its place. The page still loads, which makes this easy to miss.
Scope rules
The two tags scope differently, and this catches people out. Components get a fresh context. A component receives its ownproperties, componentId, the page data, and global. It does not see variables you set in the file that rendered it.
properties in schema.json, not through template variables.
Snippet arguments are merged into the calling context and stay set. After a render_snippet call, its arguments are still in scope for whatever comes next in the same file.
- Prefix snippet arguments with the snippet’s name, for example
header_title,header_align, so they cannot collide with anything else. - Pass every argument explicitly on every call, including the ones you want empty, rather than relying on them being unset.
snippets/section-header.njk
Email templates
Custom email templates use the same Nunjucks language, with two differences. They are structured as named blocks rather than a layout plus a body:helpers.date and helpers.price only, listed in Filters and Globals.
See Email Templates for the templates you can override, the variables each one receives, and how the shared layout works.