Nocturnal Pumpkin Maelstrom
Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

@jfrk/twig-loader

0.5.0 • Public • Published

twig-loader Build Status

Webpack loader for compiling Twig.js templates. This loader will allow you to require Twig.js views to your code.

Installation

npm install @tremby/twig-loader

Usage

Documentation: Using loaders

 
module.exports = {
    //...
 
    module: {
        rules: [
            {
                test: /\.twig$/,
                loader: "twig-loader",
                options: {
                    // See options section below
                },
            }
        ]
    },
 
    node: {
        fs: "empty" // avoids error messages
    }
};

Options

  • extender: optional; the full path to a module which exports a function(Twig) which extends Twig (such as adding filters and functions). Example: __dirname + "/src/extendTwig.js"
  • twigOptions: optional; a map of options to be passed through to Twig. Example: {autoescape: true}

Loading templates

{# File: dialog.html.twig #}
<p>{{title}}</p>
// File: app.js
var template = require("dialog.html.twig");
// => returns pre-compiled template as a function and automatically includes Twig.js to your project
 
var html = template({title: 'dialog title'});
// => Render the view with the given context
 

When you extend another view, it will also be added as a dependency. All twig functions that refer to additional templates are supported: import, include, extends & embed.

Keywords

none

Install

npm i @jfrk/[email protected]

Version

0.5.0

License

MIT

Unpacked Size

14.8 kB

Total Files

19

Last publish

Collaborators

  • avatar