metalsmith-handlebars-within

0.1.0 • Public • Published

metalsmith-handlebars-within

A metalsmith plugin to specify dynamic metadata for {{#with}} in Handlebars templates.

Installation

npm install metalsmith-handlebars-within

CLI Usage

Install the node module, and then add the metalsmith-handlebars-within key to your metalsmith.json plugins.

{
  "plugins": {
    "metalsmith-handlebars-within": {}
  }
}

There are no options for this plugin. It is intended for use alongside Handlebars and external metalsmith-metadata, for example:

{
  "plugins": {
    "metalsmith-metadata": {
      "authors": "./path/to/authors.json"
    },
    "metalsmith-handlebars-within": {},
    "metalsmith-templates": "handlebars"
  }
}

Now, within a Handlebars template, you can access a specific object in the authors.json metadata, based on a YAML variable:

{{#within authors author }}
  <a href="{{ this.url }}">{{this.name}}</a>
{{/within}}

Notes

This all seems excessive to me: it’s something I would expect to be able to access easily in Handlebars:

<a href="/about/{{ author }}">{{ authors.[author].name }}</a>

…but as far as I can tell, this isn’t possible without a Handlebars helper with author is dynamic. If I’m incorrect, please open an issue, and I’ll see if this plugin is actually necessary! Thanks.

License

The MIT License (MIT)

Copyright © 2015 Kenneth Ormandy

Package Sidebar

Install

npm i metalsmith-handlebars-within

Weekly Downloads

2

Version

0.1.0

License

MIT

Last publish

Collaborators

  • kennethormandy