Use with Assemble, Verb, or Templates.js to easily add namespaced variables like
pageorpostto the context. This allows you to use{{page.title}}instead of{{title}}to get the current page's title. Can be used with verb, assemble v0.6.0, or any application based on Templates.js.
Install with npm:
$ npm install namespace-context --save
In the example, app is assemble, verb, or any templates-based application. Just replace app with your application of choice.
var namespace = require('namespace-context');
var assemble = require('assemble');
var app = assemble();
// create the `page` namespace
app.use(namespace('page'));
// use the `page` variable in templates
app.page('abc.md', {content: '{{page.title}}'})
.render({title: 'Page Title'}, function(err, res) {
if (err) throw err;
//=> 'Page Title'
});
Works the same way with custom view collections.
var app = assemble();
app.create('posts');
// create the `post` namespace
app.use(namespace('post'));
// use the `post` variable in templates
app.post('abc.md', {content: '{{post.title}}'})
.render({title: 'Post Title'}, function(err, res) {
if (err) throw err;
//=> 'Post Title'
});
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Generate readme and API documentation with verb:
$ npm install verb && npm run docs
Or, if verb is installed globally:
$ verb
Install dev dependencies:
$ npm install -d && npm test
Jon Schlinkert
Copyright © 2016 Jon Schlinkert Released under the MIT license.
This file was generated by verb, v0.9.0, on February 25, 2016.