Include partials into your posthtml templates
npm install posthtml-include --saveGiven the following input files:
<!-- index.html -->
<p>Here's my partial:</p>
<include src='_partial.html'></include>
<p>after the partial</p><!-- _partial.html -->
<strong>hello from the partial!</strong>Process them with posthtml:
const {readFileSync} = require('fs')
const posthtml = require('posthtml')
const include = require('posthtml-include')
const html = readFileSync('index.html')
posthtml({ plugins: include() })
.process(html)
.then((result) => console.log(result.output()))Output:
<p>Here's my partial:</p>
<strong>hello from the partial!</strong>
<p>after the partial</p>All options are optional, none are required.
| Name | Description | Default |
|---|---|---|
| root | Root path to resolve the include from | the file's path |
| addDependencyTo | Object with addDependency() method, taking file path as an argument. Called whenever a file is included |
Licensed under MIT