|
||
---|---|---|
lib | ||
test | ||
.editorconfig | ||
.eslintrc | ||
.gitattributes | ||
.gitignore | ||
.travis.yml | ||
History.md | ||
Makefile | ||
package.json | ||
Readme.md |
metalsmith-layouts
A metalsmith plugin for layouts
This plugin passes your source files to a template as contents
and renders them with the templating engine of your choice. You can use any templating engine supported by consolidate.js. Pass options to metalsmith-layouts
with the Javascript API or CLI. The options are:
engine
: templating engine (required)default
: default template (optional)directory
: directory for the layouts,layouts
by default (optional)partials
: a folder to scan for partials, will register all found files as partials (optional)pattern
: only files that match this pattern will be processed (optional)
Any unrecognised options will be passed on to consolidate.js. You can use this, for example, to disable caching by passing cache: false
to consolidate. Note that passing anything but a string to the partials
option will pass the option on to consolidate. See the consolidate.js documentation for all available options.
Installation
$ npm install metalsmith-layouts
Example
Configuration in metalsmith.json
:
{
"plugins": {
"metalsmith-layouts": {
"engine": "handlebars",
"partials": "partials"
}
}
}
Source file src/index.html
:
---
layout: layout.html
title: The title
---
<p>The contents</p>
Layout layouts/layout.html
:
<!doctype html>
<html>
<head>
<title>{{title}}</title>
</head>
<body>
{{>nav}}
{{{contents}}}
</body>
</html>
Partial file partials/nav.html
:
<!-- The partial name is the path relative to the `partials` folder, without the extension -->
<nav>Nav</nav>
Results in dist/index.html
:
<!doctype html>
<html>
<head>
<title>The title</title>
</head>
<body>
<nav>Nav</nav>
<p>The contents</p>
</body>
</html>
Origins
This plugin is a fork of metalsmith-templates. Splitting up metalsmith-templates
into two plugins was suggested by Ian Storm Taylor. The results are:
- metalsmith-in-place: render templating syntax in your source files.
- metalsmith-layouts: apply layouts to your source files.
License
MIT