AMI-Twig.js is a JavaScript implementation of the Twig template engine.
Twig is a modern template engine for the PHP programming language. AMI-Twig.js is a complete rewrite of Twig for the JavaScript programming language. Both Twig and AMI-Twig.js are designed to be fast, secure and flexible. AMI-Twig.js is a standalone open source product licensed under CeCILL-C license. It is mainly maintained by Jérôme Odier.
As AMI-Twig.js is intended to run both server-side (NodeJS) and client-side (browser), some features are deliberately not implemented for performance reasons, see table below:
Tags | autoescape, block, embed, extends, filter, from, import, macro, sandbox, spaceless, use, verbatim |
---|---|
Filters | batch, convert_encoding, date, date_modify, format, number_format, striptags |
Functions | attribute, block, constant, cycle, date, dump, parent, source, template_from_string |
Tests | constant, divisibleby, sameas |
Operators | ?, ?? |
AMI-Twig.js is an essential part of the ATLAS Metadata Interface (AMI) web framework.
The primary documentation is here:
var amiTwig = require('ami-twig.min.js').amiTwig;
<script type="text/javascript" src="ami-twig.min.js"></script>
var textResult = amiTwig.engine.render(twigTemplateString, optionalDictObject);
where optionalDict contains the global variables for the template.
For optimization perposes, templates can be compiled before rendering:
var compiledTemplate = amiTwig.engine.compile(twigTemplateString);
var textResult = amiTwig.engine.render(compiledTemplateTemplate, optionalDictObject);