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.
Last updated 9 years ago by jonschlinkert .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install template 
SYNC missed versions from official npm registry.

template NPM version Build Status Coverage Status

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'));

/**
 * Create a custom view collection
 */
app.create('pages');

/**
 * Load views onto the collection (globs work too)
 */

app.page('welcome.tmpl', {path: 'welcome.tmpl', content: 'Hello, <%= name %>!'})
  .page('goodbye.tmpl', {path: 'goodbye.tmpl', content: 'Goodbye, <%= name %>!'});

// get a template
var page = app.pages.get('welcome.tmpl');

// render the template
page.render({name: 'Bob'}, function (err, res) {
  if (err) return console.log(err);
  console.log(res.content);
  //=> 'Hello, Bob!'

  app.pages.get('goodbye.tmpl')
    .render({name: 'Bob'}, function (err, res) {
      if (err) return console.log(err);
      console.log(res.content);
      //=> 'Goodbye, Bob!'
    });
});

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

Install

Install with npm

$ npm i template --save

API

See to the API documentation.

Template

Create a new instance of Template with the given `options.

Params

  • options {Object}

Example

var app = require('template')();

.data

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);
//=> {a: 'b', c: 'd'}

.create

Create a new Views collection.

Params

  • name {String}: The name of the collection. Plural or singular form.
  • opts {Object}: Collection options
  • loaders {String|Array|Function}: Loaders to use for adding views to the created collection.
  • returns {Object}: Returns the Assemble instance for chaining.

Example

app.create('foo');
app.foo('*.hbs');
var view = app.foo.get('baz.hbs');

.handle

Handle middleware for the given view and locals.

Params

  • method {String}: Router VERB
  • view {Object}: View object
  • locals {Object}
  • cb {Function}
  • returns {Object}

Example

app.handle('customHandle', view);

.compile

Compile content with the given locals.

Params

  • view {Object|String}: View object.
  • locals {Object}
  • isAsync {Boolean}: Load async helpers
  • returns {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);
// view.fn => [function]

.render

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) {
  // `view` is an object with a rendered `content` property
});

Related projects

  • assemble: Static site generator for Grunt.js, Yeoman and Node.js. Used by Zurb Foundation, Zurb Ink, H5BP/Effeckt,… more | homepage
  • en-route: Routing for static site generators, build systems and task runners, heavily based on express.js routes… more | homepage
  • layouts: Wraps templates with layouts. Layouts can use other layouts and be nested to any depth.… more | homepage
  • verb: Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used… more | homepage

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 October 31, 2015.

Current Tags

  • 0.17.5                                ...           latest (8 years ago)

60 Versions

  • 0.17.5                                ...           8 years ago
  • 0.17.4                                ...           9 years ago
  • 0.17.3                                ...           9 years ago
  • 0.17.2                                ...           9 years ago
  • 0.17.1                                ...           9 years ago
  • 0.17.0                                ...           9 years ago
  • 0.15.0                                ...           10 years ago
  • 0.14.3                                ...           10 years ago
  • 0.14.2                                ...           10 years ago
  • 0.14.1                                ...           10 years ago
  • 0.14.0                                ...           10 years ago
  • 0.13.1                                ...           10 years ago
  • 0.13.0                                ...           10 years ago
  • 0.12.6                                ...           10 years ago
  • 0.12.5                                ...           10 years ago
  • 0.12.4                                ...           10 years ago
  • 0.12.3                                ...           10 years ago
  • 0.12.2                                ...           10 years ago
  • 0.12.1                                ...           10 years ago
  • 0.12.0                                ...           10 years ago
  • 0.11.1                                ...           10 years ago
  • 0.11.0                                ...           10 years ago
  • 0.10.2                                ...           10 years ago
  • 0.10.1                                ...           10 years ago
  • 0.10.0                                ...           10 years ago
  • 0.9.3                                ...           10 years ago
  • 0.9.2                                ...           10 years ago
  • 0.9.1                                ...           10 years ago
  • 0.9.0                                ...           10 years ago
  • 0.8.0                                ...           10 years ago
  • 0.7.1                                ...           10 years ago
  • 0.7.0                                ...           10 years ago
  • 0.6.2                                ...           10 years ago
  • 0.6.1                                ...           10 years ago
  • 0.6.0                                ...           10 years ago
  • 0.5.4                                ...           10 years ago
  • 0.5.3                                ...           10 years ago
  • 0.5.2                                ...           10 years ago
  • 0.5.1                                ...           10 years ago
  • 0.5.0                                ...           10 years ago
  • 0.4.2                                ...           10 years ago
  • 0.4.1                                ...           10 years ago
  • 0.4.0                                ...           10 years ago
  • 0.3.6                                ...           10 years ago
  • 0.3.5                                ...           10 years ago
  • 0.3.4                                ...           10 years ago
  • 0.3.3                                ...           10 years ago
  • 0.3.1                                ...           10 years ago
  • 0.3.0                                ...           10 years ago
  • 0.2.1                                ...           10 years ago
  • 0.2.0                                ...           10 years ago
  • 0.1.8                                ...           11 years ago
  • 0.1.7                                ...           11 years ago
  • 0.1.6                                ...           11 years ago
  • 0.1.5                                ...           11 years ago
  • 0.1.4                                ...           11 years ago
  • 0.1.3                                ...           11 years ago
  • 0.1.2                                ...           11 years ago
  • 0.1.1                                ...           11 years ago
  • 0.1.0                                ...           11 years ago
Maintainers (2)
Downloads
Total 3
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (46)
Dev Dependencies (23)

© 2010 - cnpmjs.org x YWFE | Home | YWFE