Skip to content

Using the default Handlebars template

Yvain Liechti edited this page Mar 28, 2018 · 4 revisions

The default template (generator/Handlerbars/template) uses the default Handlebars Generator and has options that are not available in other templates.

Custom Handlebars helpers

Custom Handlebar helpers are a handy way of customizing kss-node output.

With the --helpers [directory] option, there is a simple way of loading these.

The Handlebars generator will scan the directory specified with --helpers and will require() each .js file in that directory, calling each file's returned function with the global Handlebars object as its only parameter.

Here's an example my-helpers/foo.js:

/**
 * Registers the "foo" Handlebars helper.
 *
 * @param {object} handlebars The global Handlebars object used by kss-node's kssHandlebarsGenerator.
 */
module.exports = function(handlebars) {
  handlebars.registerHelper('foo', function(arg1, arg2, options) {
    return new handlebars.SafeString('<a href="' + arg1 + '">' + arg2 + '</a>');
  });
};

Which you can load with: kss-node --helpers path/to/my-helpers