metalsmith-handlebars

1.1.0 • Public • Published

metalsmith-handlebars

A basic implimentation of handlebars for metalsmith

I made this plugin as an alternative to metalsmith-jstransformer so that the handlebars inline templating functionality can be leveraged. This means you can use handlebars like this:

src/index.hbs
---
title: Home
---
{{#> main-layout }}
    {{#* inline "content-block" }}
        Hello, welcome to my metalsmith static site.
    {{/inline}}
{{/main-layout}}
 
partials/main-layout.hbs
<html>
    <head>
    </head>
    <body>
        {{>content-block}}
    </body>
</html>
 

The plugin can be used in the metalsmith 'use' definition like this:

const Metalsmith = require('metalsmith'),
      handlebars = require('metalsmith-handlebars');
 
Metalsmith(__dirname)
    .use(handlebars({
        pattern: '**/*.hbs', // defaults to '**'
        partials: 'partials', // defaults to 'partials' in the root
        targetExtension: 'html', // defaults to html
        globals: { // defaults to an empty object
            foo: 'bar'
        }
    }))
    .build(function(err) {
        if (err) throw err;
        console.log('Build finished!');
    });

Readme

Keywords

none

Package Sidebar

Install

npm i metalsmith-handlebars

Weekly Downloads

26

Version

1.1.0

License

MIT

Last publish

Collaborators

  • robbollons