Nauseating Packaged Meat
Unleash awesomeness. Private packages, team management tools, and powerful integrations. Get started with npm Orgs »


2.1.2 • Public • Published


NPM version Build Status Coverage percentage Donate

First-class Twig engine for Node.js

Philosophy behind Twing

We believe that a first-class Twig engine should be able to render any template to the exact same result as the official PHP engine. That means that it should implement 100% of the syntax defined by the language specifications and that it should render that syntax using PHP logic.

We also believe that a first-class Twig engine should be able to catch-up easily when Twig specifications evolve. Its code architecture and philosophy should then be as close as possible as the PHP implementation.

Finally, we believe that a first-class Twig engine should allow users to build on their experience with TwigPHP and get support from the huge community that comes with it.

That's what Twing is. A maintainability-first engine that pass 100% of the TwigPHP integration tests, is as close as possible to its code structure and expose an as-close-as-possible API.


Twing needs at least node.js 6.0.0 to run but it is highly recommended to use node.js 8.x or higher to enjoy the best performance possible.


The recommended way to install Twing is via npm:

npm install twing --save

Basic API Usage

const {TwingEnvironment, TwingLoaderArray} = require('twing');
let loader = new TwingLoaderArray({
    'index.twig': 'Hello {{ name }}!'
let twing = new TwingEnvironment(loader);
let output = twing.render('index.twig', {name: 'Fabien'});

Browser support

Starting with version 2.0.0, Twing can be used in web browsers with very few compromise. Filesystem components are obviously not available (namely filesystem loader and cache) but everything else is fully supported.

Module bundler

Module bundlers will automatically grab the browser-specific flavor of Twing when Twing module is imported. Either const {TwingEnvironment} = require('twing'); or import {TwingEnvironment} from 'twing'; will work in both node.js and the browser - once bundled in the latter case.

Script tag

Use jsdelivr CDN to include Twing in your HTML document:

<script src=""></script>

Once loaded by the browser, Twing is available under the global Twing variable.

More information

Read the documentation for more information.


  • Fork this repository
  • Code
  • Implement tests using tape
  • Issue a pull request keeping in mind that all pull requests must reference an issue in the issue queue


Copyright © 2018 Eric MORAND. Released under the 2-Clause BSD License.


npm i twing

Downloadsweekly downloads









last publish


  • avatar
Report a vulnerability