@phtml/include
v4.2.0
Published
Embed HTML partials into HTML
Downloads
10
Maintainers
Readme
pHTML Include
pHTML Include lets you embed HTML partials into HTML.
<!doctype html>
<html>
<head>
<title>phtml-include</title>
</head>
<body>
<!-- where _body.html is <h1>Body Partial</h1> -->
<include src="_body.html" />
</body>
</html>
<!-- becomes -->
<!doctype html>
<html>
<head>
<title>phtml-include</title>
</head>
<body>
<h1>Body Partial</h1>
</body>
</html>
Usage
Transform HTML files directly from the command line:
npx phtml source.html output.html -p @phtml/include
Node
Add pHTML Include to your project:
npm install @phtml/include --save-dev
Use pHTML Include to process your HTML:
const phtmlInclude = require('@phtml/include');
phtmlInclude.process(YOUR_HTML /*, processOptions, pluginOptions */);
Or use it as a pHTML plugin:
const phtml = require('phtml');
const phtmlInclude = require('@phtml/include');
phtml([
phtmlInclude(/* pluginOptions */)
]).process(YOUR_HTML /*, processOptions */);
pHTML Include runs in all Node environments, with special instructions for:
| Node | CLI | Eleventy | Gulp | Grunt | | --- | --- | --- | --- | --- |
Options
cwd
The cwd
option defines and overrides the current working directory of includes.
// resolve all relative includes to /some/absolute/path
phtmlInclude({ cwd: '/some/absolute/path' });