0

I am using Pattern Lab Node v2.12.0 on Windows, with Node v8.11.1, using a Gulp Edition.

I am very confused how to actually write my own handlebars helper and use it in patternlab-node. I read there are patternlab plugins but is this the correct way to load a handlebars helper?

I hope someone can point me in the right direction. I also didn't find any information about plugins or whatsoever on the official documentation page.

Thanks in advance.

  • 1
    I don't understand why this question was voted down. It's a perfectly legit question. Thanks MiW0 for proving the answer! And to those who voted it down: there is no need to vote a question down simply if you do not understand it. If you really have to, at least have the decency to explain why. Let's be respectful. – Nookeen Jan 17 '19 at 19:20

1 Answers1

1

For anyone also interested in this, I can recommend reading the issue I opened here https://github.com/pattern-lab/patternlab-node/issues/958 or read the source code of a working plugin I finally managed to create and publish here https://www.npmjs.com/package/plugin-node-patternlab-inline-assets.

Some clues I found out while reading Pattern Lab Node's source code

  • Plugin-Folders must start with a prefix "plugin-node-" (eg. plugin-node-myplugin) so Pattern Lab can find your plugin in node_modules (and otherwise it will not be executed)
  • You can access Handlebars.js in your plugin's exported function via passed patternlab Object in patternlab.engines.handlebars.engine where you can execute registerHelper to register your Handlebars.js helper.

module.exports = (patternlab) => {
    if (!patternlab) {
        process.exit(1);
    }

    patternlab.engines.handlebars.engine.registerHelper('your-helper', (parameter) => {
        return 'your result of the helper';
    });
};

For further reading, see the poor documentation: https://github.com/pattern-lab/patternlab-node/wiki/Creating-Plugins