2017 © Pedro Peláez
 

library twigjspackagist

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

image

ajbdev/twigjspackagist

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

  • Thursday, November 16, 2017
  • by ajbdev
  • Repository
  • 1 Watchers
  • 2 Stars
  • 157 Installations
  • JavaScript
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Build Status, (*1)

About

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

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

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

Documentation is available in the twig.js wiki on Github., (*5)

Feature Support

For a list of supported tags/filters/functions/tests see the implementation notes on the wiki., (*6)

Node Usage

Twig.js can be installed with NPM, (*7)

npm install twig

You can include twig in your app with, (*8)

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., (*9)

app.js

Express 3, (*10)

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, (*11)

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

Message of the moment: <b>{{ message }}</b>

Browser Usage

Include twig.js or twig.min.js in your page, then:, (*12)

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

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

Tests

The tiwg.js tests are written in Mocha and can be invoked with make test., (*13)

License

Twig.js is available under a BSD 2-Clause License, see the LICENSE file for more information., (*14)

Acknowledgments

See the LICENSES.md file for copies of the referenced licenses., (*15)

  1. The JavaScript Array fills in src/twig.fills.js are from https://developer.mozilla.org/ and are available under the MIT License or are public domain., (*16)

  2. The Date.format function in src/twig.lib.js is from http://jpaq.org/ and used under a MIT license., (*17)

  3. The sprintf implementation in src/twig.lib.js used for the format filter is from http://www.diveintojavascript.com/projects/javascript-sprintf and used under a BSD 3-Clause License., (*18)

  4. The strip_tags implementation in src/twig.lib.js used for the striptags filter is from http://phpjs.org/functions/strip_tags and used under and MIT License., (*19)

The Versions

16/11 2017

dev-master

9999999-dev https://github.com/justjohn/twig.js/wiki

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

  Sources   Download

twig javascript