Package Exports
- twig
- twig/twig
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (twig) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
About
Twig.js is a pure JavaScript implementation of the Twig PHP templating language (http://twig.sensiolabs.org/)
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).
Supported tags:
- if / elseif / else / endif
- for / else / endfor
- set
A limited set of filters are supported (with more coming) and most of the expression syntax is implemented.
Supported filters:
upper, lower, capitalize, title, length, reverse, sort, keys, url_encode, join, default, json_encode, merge
Node Usage
Twig.js can be installed with NPM
npm install twigYou can include twig in your app with
var twig = require('twig');Twig is also compatable with express. You can create an express app using the twig templating language by setting the view engine to twig.
app.js
var twig = require("twig"),
app = require('express').createServer();
app.configure(function () {
app.set('view engine', 'twig');
app.set("view options", { layout: false });
});
app.register('twig', twig);
app.get('/', function(req, res){
res.render('index', {
message : "Hello World"
});
});
app.listen(9999);views/index.twig
Message of the moment: <b>{{ message }}</b>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."Documentation is available in the twig.js wiki
License
Twig.js is available under a BSD 2-Clause license, see the LICENSE file for more information.
Acknowledgments
The JavaScript fills in src/twig.fills.js are from https://developer.mozilla.org/ and used under a Creative Commons Attribution-ShareAlike 2.5 License
The build script makes use of Google's Closure Compiler which is used under an Apache License Version 2.0