This middleware will work with [assemble][], [verb][], [generate][], [update][] or any other node.js application based on the [templates][] library.
var pageData = require('{%= name %}');
var assemble = require('assemble');
var app = assemble();
app.onLoad(/\.md$/, pageData(app));
var page = app.page('home.md', {
contents: new Buffer('---\ntitle: Home\n---\n\nThis is {{page.title}}')
});
app.render(page, function(err, view) {
if (err) return console.log(err);
console.log(view.contents.toString());
//=> 'This is Home'
});
Then, inside templates you can use the variable like this:
Which would render to:
This is the Home page.
Optionally specify a custom property name to use instead of page
.
// you don't need to create a custom collection too, this is just an example
app.create('posts');
app.onLoad(/\.md$/, pageData(app, 'post'));
var post = app.post('home.md', {
contents: new Buffer('---\ntitle: Home\n---\n\nThis is {{post.title}}')
});
app.render(post, function(err, view) {
if (err) return console.log(err);
console.log(view.contents.toString());
//=> 'This is Home'
});