@rhinostone/swig-twig
v2.12.2
Published
Twig-syntax frontend for the @rhinostone/swig-core template engine. Part of the @rhinostone/swig multi-flavor family.
Maintainers
Readme
@rhinostone/swig-twig
Twig-syntax frontend for the @rhinostone/swig-core template engine. Part of the multi-flavor architecture introduced in 2.0.0 — see ROADMAP.md for the release narrative.
Installation
npm install @rhinostone/swig-twigThis pulls in @rhinostone/swig-core as a peer dependency, pinned to the matching version. Frontends and the core release in lockstep — do not mix versions.
Basic example
var swig = require('@rhinostone/swig-twig');
var out = swig.render('Hello, {{ name|upper }}!', {
locals: { name: 'world' }
});
// => Hello, WORLD!Supported surface
- Tags —
apply,block,extends,for,from,if,import,include,macro,set,verbatim,with. - Operators —
..range,??null-coalescing,~string concat,is <test>/is not <test>. - Built-in
istests —defined,null,empty,iterable,odd,even,divisibleby. - Unknown names — a filter or test name the instance does not hold is a compile error wherever it stands, as in Twig. Register custom filters and tests before the compile that uses them.
- Filters — the Twig core overlaps (length, lower, upper, first, last, join, reverse, sort, striptags, url_encode, json_encode, raw, escape / e, slice, split, batch, trim, number_format, replace, keys, format, merge, date). See
lib/filters.jsfor the full list.
Explicitly unsupported (parse-time throw)
{% sandbox %}— security-sandbox tag, out of scope.- The Twig tests
none,sequence,mapping,constant,true,same asanddivisible by— not provided (divisiblebyis). - Macro kwargs — use positional args.
{% use %}— not implemented.{% deprecated %}— not implemented; use comment pragmas.
Repository
Source: gina-io/swig/packages/swig-twig. File issues and PRs at gina-io/swig.
License
MIT. See LICENSE in the monorepo root.
