
Security News
CVE Volume Surges Past 48,000 in 2025 as WordPress Plugin Ecosystem Drives Growth
CVE disclosures hit a record 48,185 in 2025, driven largely by vulnerabilities in third-party WordPress plugins.
metalsmith-handlebars-x
Advanced tools
The best plugin for metalsmith + Handlebars. Global/local partials, in-place & layout compilation, and maximum flexibility.
The best plugin for metalsmith + Handlebars. Global/local partials, in-place & layout compilation, and maximum customizability.
Combines all of metalsmith-handlebars, metalsmith-handlebars-contents, metalsmith-handlebars-layouts, metalsmith-discover-helpers, metalsmith-discover-partials, @goodthnx/metalsmith-handlebars, metalsmith-nested, metalsmith-register-helpers, metalsmith-register-partials and adds more. Written out of frustration with incomplete and/or complex existing options.
patternpartialsset and call helpersNPM:
npm i -D metalsmith-handlebars-x
Yarn:
yarn add metalsmith-handlebars-x
var xhandlebars = require('metalsmith-handlebars-x');
// use defaults
metalsmith.use(xhandlebars());
// use defaults (explicit)
metalsmith.use(xhandlebars({
instance: require('handlebars'),
pattern: '**/*.{hbs,handlebars}',
layout: true,
partials: 'partials',
helpers: {},
context: (filemeta, globalmeta) => Object.assign({}, globalmeta, filemeta),
renameExtension: null
});
Set env var DEBUG to metalsmith-handlebars-x.
Linux / OSX
DEBUG=metalsmith-handlebars-x
Windows
set DEBUG=metalsmith-handlebars-x
Partials will be looked for in the directory specified in the partials option.
Partials are automatically removed from the build output unless layout: false.
A partial at partials/blockquote.hbs will be usable in templates as blockquote.
A partial at partials/layout/default.hbs will be usable in templates as layout/default.
Global partials (available to all templates) can be registered either by specifying a directory in the Metalsmith.source directory:
metalsmith.use(handlebars({ partials: 'partials' }));
or by passing the Handlebars instance to the plugin:
var Handlebars = require('handlebars');
Handlebars.registerPartial('blockquote', '<blockquote cite="{{url}}">{{ quote }}</blockquote>');
metalsmith.use(handlebars({ instance: Handlebars }));
Both can be used together!
Local partials will be available to all templates that reside in the same directory.
In the directory structure below both .md files have access to partial layout/default.
├── partials
| └── layout
| └── default.hbs
└── posts
├── partials
| └── local.hbs
├── subfolder
| └── post-without-local-partials.md
└── post-with-local-partials.md
metalsmith-handlebars-x provides 2 useful helpers by default:
call : {{ call func arg1 arg2 arg3 }} allows calling functions available in template contextset: {{ set varname value }} allows storing temporary variables for re-use in the templateRegister extra helpers through the helpers option as {[helperName]: helperFunc}, or similar to global partials,
register them directly on a Handlebars instance passed to the instance option.
Specify a custom context option to map file & global metadata in your templates, e.g:
context: function(filemeta, globalmeta) {
return {
page: filemeta,
site: globalmeta
};
}
In your templates:
{{ site.sitename }} {{ page.stats.birthTime }}
With the renameExtension option you can choose what to do with a file's extension:
null or undefined does nothing (default)"" (empty string) removes the last extension (so index.hbs would become index, while style.css.hbs would become style.css)".<ext>" renames the last extension to <ext>, for example index.hbs would become index.html if renameExtension: '.html'.Relatively straight-forward:
const Handlebars = require('handlebars');
const hbsLayouts = require('handlebars-layouts')(Handlebars);
const xhandlebars = require('metalsmith-handlebars-x');
Handlebars.registerHelper(hbsLayouts);
metalsmith.use(xhandlebars({ instance: Handlebars }));
You can use this plugin together with @metalsmith/layouts & metalsmith-discover-partials but you should specify layout: false in order to avoid conflicts. metalsmith-handlebars-x will then only compile file contents. See test.js for an example.
FAQs
The best plugin for metalsmith + Handlebars. Global/local partials, in-place & layout compilation, and maximum flexibility.
We found that metalsmith-handlebars-x demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
CVE disclosures hit a record 48,185 in 2025, driven largely by vulnerabilities in third-party WordPress plugins.

Security News
Socket CEO Feross Aboukhadijeh joins Insecure Agents to discuss CVE remediation and why supply chain attacks require a different security approach.

Security News
Tailwind Labs laid off 75% of its engineering team after revenue dropped 80%, as LLMs redirect traffic away from documentation where developers discover paid products.