template
Render templates using any engine. Supports, layouts, pages, partials and custom template types. Use template helpers, middleware, routes, loaders, and lots more. Powers assemble, verb and other node.js apps.
Introduction
Here is a brief example of what you can do with Template.
var app = require('template')();
app.engine('tmpl', require('engine-lodash'));
app.create('pages');
app.page('welcome.tmpl', {path: 'welcome.tmpl', content: 'Hello, <%= name %>!'})
.page('goodbye.tmpl', {path: 'goodbye.tmpl', content: 'Goodbye, <%= name %>!'});
var page = app.pages.get('welcome.tmpl');
page.render({name: 'Bob'}, function (err, res) {
if (err) return console.log(err);
console.log(res.content);
app.pages.get('goodbye.tmpl')
.render({name: 'Bob'}, function (err, res) {
if (err) return console.log(err);
console.log(res.content);
});
});
Docs are on the way. In the meantime, visit the examples and unit tests to learn more about what Template can do.
Table of contents
(Table of contents generated by verb)
Install
Install with npm
$ npm i template --save
API
See to the API documentation.
Create a new instance of Template
with the given `options.
Params
Example
var app = require('template')();
Load data onto app.cache.data
Params
key
{String|Object}: Key of the value to set, or object to extend.val
{any}returns
{Object}: Returns the instance of Template
for chaining
Example
console.log(app.cache.data);
app.data('a', 'b');
app.data({c: 'd'});
console.log(app.cache.data);
Create a new Views
collection.
Params
- {String}: name The name of the collection. Plural or singular form.
- {Object}: opts Collection options
- {String|Array|Function}: loaders Loaders to use for adding views to the collection.
returns
{Object}: Returns the instance for chaining.
Example
app.create('foo');
app.foo('*.hbs');
var view = app.foo.get('baz.hbs');
Handle middleware for the given view
and locals.
Params
method
{String}: Router VERBview
{Object}: View objectlocals
{Object}cb
{Function}returns
{Object}
Example
app.handle('customHandle', view);
Compile content
with the given locals
.
Params
view
{Object|String}: View object.locals
{Object}isAsync
{Boolean}: Load async helpersreturns
{Object}: View object with fn
property with the compiled function.
Example
var blogPost = app.post('2015-09-01-foo-bar');
var view = app.compile(blogPost);
Render content
with the given locals
and callback
.
Params
file
{Object|String}: String or normalized template object.locals
{Object}: Locals to pass to registered view engines.callback
{Function}
Example
var blogPost = app.post('2015-09-01-foo-bar');
app.render(blogPost, function(err, view) {
});
Related projects
- assemble: Static site generator for Grunt.js, Yeoman and Node.js. Used by Zurb Foundation, Zurb Ink, H5BP/Effeckt,… more
- en-route: Routing for static site generators, build systems and task runners, heavily based on express.js routes… more
- layouts: Wraps templates with layouts. Layouts can use other layouts and be nested to any depth.… more
- verb: Documentation generator for GitHub projects. Extremely powerful, easy to use, can generate anything from API… more
Running tests
Install dev dependencies:
$ npm i -d && npm test
Build docs
Install devDependencies:
npm i -d && verb
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue
Authors
Jon Schlinkert
License
Copyright © 2014-2015 Jon Schlinkert
Released under the MIT license.
This file was generated by verb-cli on August 19, 2015.