{{ AMI-Twig.js }}

AMI-Twig.js is a JavaScript implementation of the Twig template engine.

Download AMI-Twig.js

What is AMI-Twig.js?

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.

Getting started

The primary documentation is here:

Loading AMI-Twig.js server-side:

var amiTwig = require('ami-twig.min.js').amiTwig;

Loading AMI-Twig.js client-side:

<script type="text/javascript" src="ami-twig.min.js"></script>

Using AMI-Twig.js:

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);

Try AMI-Twig.js


						

Contact

AMI Team
LPSC Grenoble,
amilpsc.in2p3.fr