No description
Find a file
2015-08-07 17:41:51 +02:00
lib Add partials option 2015-08-07 16:10:22 +02:00
test Refactor partials tests 2015-08-07 17:37:19 +02:00
.editorconfig Add dotfiles 2015-07-25 11:22:36 +02:00
.eslintrc Update eslint config 2015-08-07 16:18:02 +02:00
.gitattributes Add dotfiles 2015-07-25 11:22:36 +02:00
.gitignore first commit 2014-02-04 21:47:35 -08:00
.travis.yml Add travis 2015-07-16 21:05:15 +02:00
History.md 1.3.0 2015-08-07 16:48:12 +02:00
Makefile Update eslint config 2015-08-06 17:04:59 +02:00
package.json 1.3.0 2015-08-07 16:48:12 +02:00
Readme.md Update readme 2015-08-07 16:26:10 +02:00

metalsmith-layouts

npm Build Status Dependency Status devDependency Status npm

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:

License

MIT