PHPackages                             ajbdev/twigjspackagist - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. ajbdev/twigjspackagist

ActiveLibrary

ajbdev/twigjspackagist
======================

Twig.js is a pure JavaScript implementation of the Twig PHP templating language (http://twig.sensiolabs.org/)

2167JavaScript

Since Nov 16Pushed 8y ago1 watchersCompare

[ Source](https://github.com/ajbdev/twigjspackagist)[ Packagist](https://packagist.org/packages/ajbdev/twigjspackagist)[ RSS](/packages/ajbdev-twigjspackagist/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

[![Build Status](https://camo.githubusercontent.com/05712702f87a6af05b9a81f2f08b50d243584e45ddbedc8bdc7fa50f3294a02d/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f6a7573746a6f686e2f747769672e6a732e706e67)](http://travis-ci.org/#!/justjohn/twig.js)

About
=====

[](#about)

Twig.js is a pure JavaScript implementation of the Twig PHP templating language ()

The goal is to provide a library that is compatible with both browsers and server side containers such as node.js.

Twig.js is currently a work in progress and supports a limited subset of the Twig templating language (with more coming).

Documentation is available in the [twig.js wiki](https://github.com/justjohn/twig.js/wiki) on Github.

### Feature Support

[](#feature-support)

For a list of supported tags/filters/functions/tests see the [implementation notes on the wiki](https://github.com/justjohn/twig.js/wiki/Supported-Features---Implementation-Notes).

Node Usage
==========

[](#node-usage)

Twig.js can be installed with NPM

```
npm install twig

```

You can include twig in your app with

```
var twig = require('twig');

```

Twig is compatable with express 2 and 3. You can create an express app using the twig.js templating language by setting the view engine to twig.

app.js
------

[](#appjs)

**Express 3**

```
var Twig = require("twig"),
    express = require('express'),
    app = express();

// This section is optional and used to configure twig.
app.set("twig options", {
    strict_variables: false
});

app.get('/', function(req, res){
  res.render('index.twig', {
    message : "Hello World"
  });
});

app.listen(9999);
```

**Express 2**

```
var twig = require("twig"),
    app = require('express').createServer();

app.configure(function () {
    app.set('view engine', 'twig');
    app.set("view options", { layout: false });

    // This section is optional and used to configure twig.
    app.set("twig options", {
        strict_variables: false
    });
});

app.register('twig', twig);

app.get('/', function(req, res){
  res.render('index', {
    message : "Hello World"
  });
});

app.listen(9999);
```

views/index.twig
----------------

[](#viewsindextwig)

```
Message of the moment: {{ message }}
```

Browser Usage
=============

[](#browser-usage)

Include twig.js or twig.min.js in your page, then:

```
var template = twig({
    data: 'The {{ baked_good }} is a lie.'
});

console.log(
    template.render({baked_good: 'cupcake'})
);
// outputs: "The cupcake is a lie."
```

Tests
=====

[](#tests)

The tiwg.js tests are written in [Mocha](http://mochajs.org/) and can be invoked with `make test`.

License
=======

[](#license)

Twig.js is available under a [BSD 2-Clause License](http://www.opensource.org/licenses/BSD-2-Clause), see the LICENSE file for more information.

Acknowledgments
===============

[](#acknowledgments)

See the LICENSES.md file for copies of the referenced licenses.

1. The JavaScript Array fills in src/twig.fills.js are from  and are available under the [MIT License](http://www.opensource.org/licenses/mit-license.php) or are [public domain](https://developer.mozilla.org/Project:Copyrights).
2. The Date.format function in src/twig.lib.js is from  and used under a [MIT license](http://jpaq.org/license/).
3. The sprintf implementation in src/twig.lib.js used for the format filter is from  and used under a [BSD 3-Clause License](http://www.opensource.org/licenses/BSD-3-Clause).
4. The strip\_tags implementation in src/twig.lib.js used for the striptags filter is from [http://phpjs.org/functions/strip\_tags](http://phpjs.org/functions/strip_tags) and used under and [MIT License](http://phpjs.org/pages/license/#MIT).

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 91.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/7b0842f020a6b6eb2158be81dd79dae672267fada8c073ee5861febfcbfbfbbe?d=identicon)[ajbdev](/maintainers/ajbdev)

---

Top Contributors

[![justjohn](https://avatars.githubusercontent.com/u/139978?v=4)](https://github.com/justjohn "justjohn (211 commits)")[![ajbdev](https://avatars.githubusercontent.com/u/572055?v=4)](https://github.com/ajbdev "ajbdev (18 commits)")[![mortonfox](https://avatars.githubusercontent.com/u/495892?v=4)](https://github.com/mortonfox "mortonfox (1 commits)")

### Embed Badge

![Health badge](/badges/ajbdev-twigjspackagist/health.svg)

```
[![Health](https://phpackages.com/badges/ajbdev-twigjspackagist/health.svg)](https://phpackages.com/packages/ajbdev-twigjspackagist)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
