Skip to content

Latest commit

 

History

History
56 lines (42 loc) · 1.22 KB

File metadata and controls

56 lines (42 loc) · 1.22 KB

Usage

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:

---
title: Home
---

This is the {{page.title}} page.

Which would render to:

This is the Home page.

Custom variable

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