All Projects → twigjs → Twig.js

twigjs / Twig.js

Licence: bsd-2-clause
JS implementation of the Twig Templating Language

Programming Languages

javascript
184084 projects - #8 most used programming language
Twig
543 projects

Labels

Projects that are alternatives of or similar to Twig.js

Twigfiddle
twigfiddle.com provides a small development environment to develop, run, store and access Twig code online.
Stars: ✭ 87 (-94.97%)
Mutual labels:  twig
Twig Extensions
Twig extensions
Stars: ✭ 1,469 (-15.14%)
Mutual labels:  twig
Craft
Composer starter project for Craft CMS
Stars: ✭ 122 (-92.95%)
Mutual labels:  twig
Cssinliner Extra
CSS Inliner support for Twig
Stars: ✭ 93 (-94.63%)
Mutual labels:  twig
Markdown Extension
[DEPRECATED] Markdown support for Twig
Stars: ✭ 105 (-93.93%)
Mutual labels:  twig
Twital
Twital is a "plugin" for Twig that adds some sugar syntax, which makes its templates similar to PHPTal or VueJS.
Stars: ✭ 116 (-93.3%)
Mutual labels:  twig
Kimai2
Kimai v2 is a web-based multiuser time-tracking application. Free for everyone: freelancers, agencies, companies, organizations - all can track their times, generate invoices and more. SaaS version available at https://www.kimai.cloud
Stars: ✭ 1,216 (-29.75%)
Mutual labels:  twig
Chyrp Lite
An ultra-lightweight blogging engine, written in PHP.
Stars: ✭ 131 (-92.43%)
Mutual labels:  twig
Knppaginatorbundle
SEO friendly Symfony paginator to sort and paginate
Stars: ✭ 1,534 (-11.38%)
Mutual labels:  twig
Symfony Demo App
A Symfony demo application with basic user management
Stars: ✭ 122 (-92.95%)
Mutual labels:  twig
Nodefony Starter
Nodefony Starter Node.js Framework
Stars: ✭ 95 (-94.51%)
Mutual labels:  twig
Twig
Twig - less is more's web server for golang
Stars: ✭ 98 (-94.34%)
Mutual labels:  twig
Stitcher Core
High performance, static websites for PHP developers
Stars: ✭ 120 (-93.07%)
Mutual labels:  twig
String Extra
Unicode/String support for Twig
Stars: ✭ 92 (-94.69%)
Mutual labels:  twig
Yii2 Twig
Yii 2 Twig extension.
Stars: ✭ 130 (-92.49%)
Mutual labels:  twig
Platform
Shopware 6 is an open source eCommerce platform realised by the ideas and the spirit of its community.
Stars: ✭ 1,267 (-26.81%)
Mutual labels:  twig
User Bundle
A new Symfony user bundle
Stars: ✭ 116 (-93.3%)
Mutual labels:  twig
Www.php Fig.org
Source for the PHP-FIG website
Stars: ✭ 135 (-92.2%)
Mutual labels:  twig
Stick
A golang port of the Twig templating engine
Stars: ✭ 132 (-92.37%)
Mutual labels:  twig
Detoxify App
📱🙅 Generate a fake app to replace any addictive app
Stars: ✭ 122 (-92.95%)
Mutual labels:  twig

Known Vulnerabilities Build Status NPM version Gitter

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 JavaScript environments 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).

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/twigjs/twig.js/releases or via NPM:

npm install twig --save

Bower

A bower package is available from philsbury. Please direct any Bower support issues to that repo.

Browser Usage

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

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

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

Webpack

A loader is available from zimmo.be.

Node Usage (npm)

Tested on node >=6.0.

You can use twig in your app with

var Twig = require('twig'), // Twig module
    twig = Twig.twig;       // Render function

Usage without Express

If you don't want to use Express, you can render a template with the following method:

import Twig from 'twig';
Twig.renderFile('./path/to/someFile.twig', {foo:'bar'}, (err, html) => {
  html; // compiled string
});

Usage with Express

Twig is compatible 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

Express 3

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

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

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

app.listen(9999);

views/index.twig

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

An Express 2 Example is available on the wiki.

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.

twig.js is built by running npm run build

For more details on getting setup, see the contributing page on the wiki.

Environment Requirements

When developing on Windows, the repository must be checked out without automatic conversion of LF to CRLF. Failure to do so will cause tests that would otherwise pass on Linux or Mac to fail instead.

Tests

The twig.js tests are written in Mocha and can be invoked with npm test.

License

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

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/twig.lib.js is from http://jpaq.org/ and used under a MIT license.

  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.

  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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].