🚀 Launch Week Day 2:Introducing Custom Tabs for Org Alerts.Learn More →
Socket
Book a DemoInstallSign in
Socket

helper-front-matter

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

helper-front-matter

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

latest
Source
npmnpm
Version
0.1.0
Version published
Maintainers
1
Created
Source

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.

Keywords

context

FAQs

Package last updated on 10 Apr 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts