简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM