A metalsmith plugin to specify dynamic metadata for {{#with}} in Handlebars templates.
npm install metalsmith-handlebars-within
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}}
This all seems excessive to me: it’s something I would expect to be able to access easily in Handlebars:
…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.
Copyright © 2015 Kenneth Ormandy