npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

template

v0.17.5

Published

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.

Downloads

15,850

Readme

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.