Skip to content

JS implementation of the Twig Templating Language

License

Notifications You must be signed in to change notification settings

LangiviTechnology/twig.js

 
 

Repository files navigation

Deno

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 server side JavaScript environment such as deno.js.

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

Docs

Documentation is available in the twig.js wiki on Github.

Feature Support

For a list of supported tags/filters/functions/tests see the Implementation Notes page on the wiki.

Install

Download the latest twig.js release from github: https://github.com/LangiviTechnology/twig.js or via deno.land:

import Twig, {renderToString} from 'https://deno.land/x/twig@1.16.2/mod.js'

Usage with Opine

Twig is compatible with Opine. You can create an opine app using the twig.js templating language by setting the view engine to twig.

app.js

opine 2.1.3

import opine from "https://deno.land/x/opine@2.1.3/mod.ts";
import {renderToString} from "../../src/twig.js";

const app = opine();
//specifies a function to process the template
app.engine('twig', renderToString);
//specify the folder with templates
app.set('views',"./view");
app.set('view engine', 'twig');
app.set('view cache', true);

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

views/index.twig

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

Alternatives

Contributing

If you have a change you want to make to twig.js, feel free to fork this repository and submit a pull request on Github. The source files are located in src/*.js.

Acknowledgments

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

  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.

  2. The Date.format function in src/TwigLib.js is from http://jpaq.org/ and used under a MIT license.

  3. The sprintf implementation in src/TwigLib.js used for the format filter is from http://www.diveintojavascript.com/projects/javascript-sprintf and used under a BSD 3-Clause License.

  4. The strip_tags implementation in src/TwigLib.js used for the striptags filter is from http://phpjs.org/functions/strip_tags and used under and MIT License.

About

JS implementation of the Twig Templating Language

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 98.3%
  • Twig 1.5%
  • Other 0.2%