Skip to content

LookThink/twigjs-loader

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

twigjs-loader

Build Status npm version Dependencies status

Description

twig.js loader for Webpack

Installation

This package requires node.js 8 at least.

Install with npm:

$ npm i -D twigjs-loader

Usage

var indexView = require('./index.twig');
console.log(indexView({ variable1: 'value' });

webpack.config.js

module.exports = {
  ...
  module: {
    rules: [
      {
        test: /\.twig$/,
        use: 'twigjs-loader',
        options: {
          functions: {
            someFunction: function() {
              return true;
            },
          }
        }
      },
      ...
  },
  ...
}

Options

Name Type Default Description
functions object undefined Extends Twig with custom functions

With Express

example, typescript example

$ npm i twigjs-loader

index.js:

import * as express from "express";
import { ExpressView } from "twigjs-loader";
import indexView from "./views/index.twig";

const app = express();
app.set("view", ExpressView);

app.get("/", (req, res) => {
  res.render(indexView, {
    url: `${req.protocol}://${req.get("host")}${req.originalUrl}`,
  })
});

const port = process.env.NODE_PORT || 8080;
app.listen(port, () => {
  console.log(`Example app listening on port ${port}.`);
});

License

Licensed under MIT.

Credits

Based on zimmo-be/twig-loader

About

twig.js loader for Webpack

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 78.3%
  • HTML 21.7%