Skip to content
Embed HTML partials in HTML
JavaScript HTML
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
test
.editorconfig
.gitignore
.rollup.js
.tape.js
.travis.yml
CHANGELOG.md
CONTRIBUTING.md
INSTALL.md
LICENSE.md
README.md
package.json

README.md

pHTML Include pHTML

NPM Version Build Status Support Chat

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' });
You can’t perform that action at this time.