metalsmith-nested
A metalsmith plugin for nesting your layouts when using the handlebars engine.
This plugin extends metalsmith-layouts
when using the handlebars
layout engine
and recursively combines (nests) layouts in parent-child relationships.
Simple enough it might also work with other layout engines.
Installation
$ npm install --save metalsmith-nested
Example
Child layouts are nested inside parent layouts replacing the
{{{contents}}}
expression.
Configuration in metalsmith.json
:
Source Page src/page.html
:
---layout: child.htmlheading: Page Headingtitle: Page Title---Page contents
Child Layout nested/child.html
:
---layout: parent.html---{{heading}} {{{contents}}}
Parent Layout nested/parent.html
:
{{title}} {{{contents}}}
Results in layouts/child.html
:
{{title}} {{heading}} {{{contents}}}
Results in build/page.html
:
Page Title Page Heading Page contents
It is possible to combine (nest) multiple layouts.
Example Site
Copy the example
directory outside of the metalsmith-nested
package
$ cp -rf example ../example
Navigate to the example
directory
$ cd ../example
Install the dependencies
$ npm install
Build the site
$ node build
Javascript Build Script
The following build script uses the default values for all packages
except that handlebars
is specified as the layout engine.
[build.js]
const Metalsmith = handlebars = layouts = nested = ; source'src' ;
the above is the same as
[build.js]
const Metalsmith = handlebars = layouts = nested = ; ;
The important thing to know is that the directory
for metalsmith-nested
is the source directory of pre-nested layouts and the generated
directory
is the output of combined (nested) layouts.
The output of metalsmith-nested is the input of metalsmith-layouts
Other options are pattern
and default
which should behave the same as in metalsmith-layouts.
See metalsmith-layouts and
multimatch for full documentation.
All Available Options
directory: 'nested'generated: 'layouts'pattern: '**/*'default: ''
License
MIT