- Notifications
You must be signed in to change notification settings - Fork74
Webpack loader for compiling Twig.js templates
License
zimmo-be/twig-loader
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Webpack loader for compiling Twig.js templates. This loader will allow you to require Twig.js views to your code.
npm install twig-loader
module.exports={//...module:{rules:[{test:/\.twig$/,use:{loader:'twig-loader',options:{// See options section below},}}]},node:{fs:"empty"// avoids error messages}};
module.exports={//...module:{rules:[{test:/\.twig$/,loader:"twig-loader",options:{// See options section below},}]},node:{fs:"empty"// avoids error messages}};
twigOptions
: optional; a map of options to be passed through to Twig.Example:{autoescape: true}
{# File: dialog.html.twig#}<p>{{title}}</p>
// File: app.jsvartemplate=require("dialog.html.twig");// => returns pre-compiled template as a function and automatically includes Twig.js to your projectvarhtml=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.
twig-loader will only resolve static paths in your templates, according to your webpack configuration.When you want to use dynamic templates or aliases, they cannot be resolved by webpack, and will beleft untouched in your template. It is up to you to make sure those templates are available in Twigat runtime by registering them yourself:
vartwig=require('twig').twigtwig({id:'your-custom-template-id,data: '<p>yourtemplatehere</p>',allowInlineIncludes:true,rethrow:true});
Or more advanced when usingwebpack.context
:
vartwig=require('twig').twigvarcontext=require.context('./templates/',true,/\.twig$/)context.keys().forEach(key=>{vartemplate=context(key);twig({id:key,// key will be relative from `./templates/`data:template.tokens,// tokens are exported on the template functionallowInlineIncludes:true,rethrow:true});});
- Upgrade mocha to fix security vulnerability warning
- Add ablity to pass options to twig (PR #39)
- Update to Twig.js 1.10, fixes #29
- replace full path with a hash and implement mapcache for id/path resolution, fixes #12
- Downgrade Twig.js back to 0.8.9 because oftwigjs/twig.js#440
- Improve watch operation (rebuilding of modules)
- Refactoring so compiler and the loader are in seperate modules
- Add Twig as peer dependency
- Add
embed
support - Update Twig.js version
- Improve
import
support (#8) - Rethrow exceptions when they occur during rendering to improve testing
- Add support for import statements (useful for Macro's)
- Correctly resolve dependencies from include/import/extend statements with relative path support: [#3] and [#5]
- CHANGE: No longer add the
.twig
file extension. After upgrading twig-loader, you may need to update your files and add.twig
manually
About
Webpack loader for compiling Twig.js templates