Skip to content
This repository has been archived by the owner on May 24, 2024. It is now read-only.

dane-harnett/twigify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

twigify

twigify is a Browserify transform for creating modules of pre-compiled Twig.js templates.

Installation

With npm as a local development dependency:

npm install --save-dev twigify

Usage

In templates/test.twig:

<h1>{{ title }}</h1>

In test.js:

var template = require('./templates/test.twig');
var body = template.render({
  title: 'Main Page'
});
$('body').html(body);

Including sub templates:

In templates/main.twig:

<h1>{{ title }}</h1>
{% include 'body.twig' %}

In main.js:

// need to require() this so that it is available for main.twig
var bodyTemplate = require('./templates/body.twig');
var mainTemplate = require('./templates/main.twig');

var page = mainTemplate.render({
  title: 'Main Page'
});
$('body').html(page);

Transforming with the command-line

browserify test.js -t twigify > test-bundle.js

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published