Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including metalsmith-handlebars-contents with all npm packages installed. Try it out:

var metalsmithHandlebarsContents = require("metalsmith-handlebars-contents")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

metalsmith-handlebars-contents v1.0.3

Metalsmith plugin that processes file contets with handlebars.


Processes file contents with Handlebars. Typically used for mustache syntax embedded within markdown files, but can easily process any type of text file. Safe to use with live reloading. Very similar to metalsmith-hbt-md, but this is safe to use with live reloading using metalsmith-serve and metalsmith-watch.

What It Does

Imagine you have some data in a page that you want to render as a table. This lets you repeat content using mustache and it can draw from the metadata of the file.

        name: Bob
        type: Elephant
        name: Sally
        type: Rhino

Welcome to my zoo! Right now we are taking care of the following animals

| Name | Type of Animal |
{{tableData}}| {{name}} | {{type }} |

Partials can also be used, as can helpers and other features that handlebars provides.


npm can do this for you.

npm install --save metalsmith-handlebars-contents


Include this like you would include any other plugin. Here's a CLI example that also shows the default options. You don't need to specify any of these unless you want to change its value.

    "plugins": {
        "metalsmith-handlebars-contents": {
            "data": [],
            "decorators": [],
            "helpers": [],
            "match": "**/*.md",
            "matchOptions": {},
            "partials": ["./partials/**/*"]

And this is how you use it in JavaScript, with a small description of each option.

// Load this, just like other plugins.
var handlebarsContents = require("metalsmith-handlebars-contents");

// Then in your list of plugins you use it.

// Alternately, you can specify options.  The values shown here are
// the defaults.
    // Data files to load or data objects to add to global data.
    data: [],

    // Decorators to add
    decorators: [],

    // Helper functions to include
    helpers: [],

    // Pattern of files to match in case you want to limit processing
    // to specific files.
    match: "**/*.md",

    // Options for matching files.  See metalsmith-plugin-kit for
    // more information.
    matchOptions: {},

    // Directories that hold partials for processing the content
    partials: ['./partials/**/*']

The items in the data, decorators, helpers, and partials arrays can be strings or objects. They are passed to handlebars-wax using the appropriate method.

This uses metalsmith-plugin-kit to match files. The .matchOptions object can be filled with options to control how files are matched.


This plugin is licensed under the [MIT License][License] with an additional non-advertising clause. See the [full license text][License] for information.

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free