Handlebars + Helpers Together
Handlebars + Handlebars-helpers (helpers are now maintained in this project) combined into a single package. Easily use it as a drop in replacement when using handlebars directly. More than 180 Handlebars helpers in ~20 categories. Helpers can be used with Assemble, Generate, Verb, Ghost, gulp-handlebars, grunt-handlebars, consolidate, or any node.js/Handlebars project. Currently 189 helpers in 20 categories! 🎉
npm install @jaredwray/fumanchu --save
var {handlebars, helpers} = require('@jaredwray/fumanchu');
helpers({ handlebars: handlebars });
var template = handlebars.compile('{{#if (eq foo "bar")}}<p>Foo is bar</p>{{/if}}');
var html = template({foo: 'bar'});
console.log(html);
If using it with es6 you can access handlebars
and helpers
:
import {handlebars, helpers} from '@jaredwray/fumanchu';
helpers({ handlebars: handlebars });
const template = handlebars.compile('{{#if (eq foo "bar")}}<p>Foo is bar</p>{{/if}}');
const html = template({foo: 'bar'});
console.log(html);
If you want to just get an instance of handlebars via createHandlebars
you can do the following (it is async):
import {createHandlebars} from '@jaredwray/fumanchu';
const handlebars = await createHandlebars(); //this will return a handlebars instance with all helpers
const template = handlebars.compile('{{#if (eq foo "bar")}}<p>Foo is bar</p>{{/if}}');
const html = template({foo: 'bar'});
console.log(html); // <p>Foo is bar</p>
It's just that easy! No need to add Handlebars to your project, it's already included.
If you only want to use handlebar helpers you can easily do that by doing the following:
var {helpers} = require('@jaredwray/fumanchu');
var handlebars = require('handlebars');
var helpersFunction = await helpers();
helpersFunction({ handlebars: handlebars });
var fn = handlebars.compile('{{add value 5}}');
console.log(fn); // 10
If using it with es6 you can access helpers
via destructuring:
import {helpers} from '@jaredwray/fumanchu';
import handlebars from 'handlebars';
const helpersFunction = await helpers();
helpersFunction({ handlebars: handlebars });
const template = handlebars.compile('{{#if (eq foo "bar")}}<p>Foo is bar</p>{{/if}}');
const html = template({foo: 'bar'});
console.log(html); // <p>Foo is bar</p>
clone the repository locally and run 'npm i' in the root. Now that you've set up your workspace, you're ready to contribute changes to the fumanchu
repository you can refer to the CONTRIBUTING guide. If you have any questions please feel free to ask by creating an issue and label it question
.
To test the legacy helpers, you can run npm run test:legacy
to run the tests. If you want to test the new helpers, you can run npm run test
.
MIT and codebase after 2023 will be copyright of Jared Wray.
This is a fork of handlebars-helpers which is licensed under MIT. Initial copyright of handlebars-helpers: 2013-2015, 2017, Jon Schlinkert, Brian Woodward
. Thank you so much for your effort and building this! We have also continued to list all contributors in package.json
to ensure that they are recognized.