javascripthandlebars.jspatternlab.io

How to write my own handlebars helper and use it in patternlab-node?


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.


Solution

  • 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

    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