A fork of https://github.com/mrmlnc/posthtml-mixins with a few small updates
A PostHTML plugin adds support for partials. partials allow you to create reusable blocks of code.
$ npm i -D posthtml-partials
const { readFileSync } = require('fs');
const posthtml = require('posthtml');
const partials = require('posthtml-partials');
const html = readFileSync('index.html');
posthtml([ partials() ])
.process(html)
.then((result) => console.log(result.html))
- Type:
String[]
- Default:
['{{', '}}']
Array containing beginning and ending delimiters for locals.
For example:
['{', '}']
-{ key }
['${', '}']
-${ key }
['%', '%']
-%key%
['%', '']
-%key
We support parameters for partials inside tags and in attributes.
<partial name="say" class from>
<p class="{{ class }}">Hello from {{ from }}!</p>
</partial>
<div>
<partial name="say" class="hello" from="me"></partial>
</div>
<div>
<p class="hello">Hello from me!</p>
</div>
We support default values for parameters (order is unimportant).
<partial name="say" class from="me">
<p class="{{ class }}">Hello from {{ from }}!</p>
</partial>
<div>
<partial name="say" class="hello"></partial>
</div>
<div>
<p class="hello">Hello from me!</p>
</div>
We support Partial reloading when the Partial may have the same name but a different number of parameters.
<partial name="say" from>
<p>Hello from {{ from }}!</p>
</partial>
<partial name="say">
<p>Hello!</p>
</partial>
<div>
<partial name="say"></partial>
</div>
<div>
<partial name="say" from="partial"></partial>
</div>
<div>
<p>Hello!</p>
</div>
<div>
<p>Hello from partial!</p>
</div>
See the Releases section of our GitHub project for changelogs for each release version.
This software is released under the terms of the MIT license.