0.1.0 • Published 11 years ago
helper-front-matter v0.1.0
helper-front-matter 
Template helper for parsing front matter and passing the data to templates as context.
Install with npm
npm i helper-front-matter --saveUsage
First, let's register another cutomer helper for this example:
var fs = require('fs');
var handlebars = require('handlebars');
var matter = require('helper-front-matter')(handlebars);Register the helper
// this is our helper
handlebars.registerHelper('matter', matter(handlebars));
// these are extra helpers we'll use for examples
handlebars.registerHelper('markdown', require('helper-markdown'));
handlebars.registerHelper('read', function (fp) {
return fs.readFileSync(fp, 'utf8');
});Create some templates
Given you have a file, abc.hbs, with the following contents:
---
title: ABC
foo: bar
---
## This is {{title}}
> this is a blockquoteUse the helpers
Used with the markdown helper as a block helper:
{{#markdown}}
# Heading
{{{matter (read "fixtures/abc.hbs")}}}
{{/markdown}}Renders to:
<h1>Heading</h1>
<h2>This is ABC</h2>
<blockquote>
<p>this is a blockquote</p>
</blockquote>Used with the markdown helper as an inline helper:
{{{markdown (matter (read "fixtures/abc.hbs"))}}}Renders to:
<h2>This is ABC</h2>
<blockquote>
<p>this is a blockquote</p>
</blockquote>Running tests
Install dev dependencies:
npm i -d && npm testContributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue
Author
Jon Schlinkert
License
Copyright (c) 2015 Jon Schlinkert
Released under the MIT license
This file was generated by verb-cli on April 09, 2015.
0.1.0
11 years ago