Metalsmith JSTransformer Partials
Metalsmith plugin to add partial support through any JSTransformer.
Installation
npm install --save metalsmith-jstransformer-partials
CLI
If you are using the command-line version of Metalsmith, you can install via npm, and then add the metalsmith-jstransformer-partials
key above metalsmith-jstransformer
in your metalsmith.json
file:
JavaScript API
If you are using the JavaScript API for Metalsmith, then you can require the module and add it to your .use()
directives above metalsmith-jstransformer
:
var partials = ;var jstransformer = ; metalsmith;metalsmith;
Usage
Partials are automatically defined in the partials/
directory, but you are able to define them manually by adding partials: true
to your file metadata. The following example using Swig, so ensure you also install jstransformer-swig
. To call a partial, invoke partial(<partialname>, locals)
or `partials:
src/partials/name.swig
---partial: truename: Default Name---Name: {{ name }}
src/index.html.swig
{{ partial('name', { name: 'TJ Holowaychuk' })|safe }}
Result
Name: TJ Holowaychuk
Options
.pattern
The pattern in which to automatically detect partials, without having to set partial: true
. Defaults to partials/**
.
.partials
An array of already existing partials to add to the array.
License
MIT