helper-front-matter

0.1.0 • Public • Published

helper-front-matter NPM version

Template helper for parsing front matter and passing the data to templates as context.

Install with npm

npm i helper-front-matter --save

Usage

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 blockquote

Use 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 test

Contributing

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.

Package Sidebar

Install

npm i helper-front-matter

Weekly Downloads

2

Version

0.1.0

License

MIT

Last publish

Collaborators

  • jonschlinkert
  • doowb