简体   繁体   English

使用RequireJS的amdefine工作在基于Web的项目中组装自定义帮助程序

[英]Making Custom Helpers in Assemble using RequireJS's amdefine work for a web-based project

So I have this project where I use Assemble ( http://assemble.io/docs/ ) as my static site generator, and I have made a couple of customer handlebars helpers ( http://assemble.io/docs/Custom-Helpers.html ) to use when assembling my pages. 因此,在这个项目中,我将Assemble( http://assemble.io/docs/ )用作静态站点生成器,并制作了几个客户车把帮助器( http://assemble.io/docs/Custom-组装页面时使用的Helpers.html )。

This all works fine, I reference the helper file within my grunt task, runs a "grunt serve" and voila, my assembled handlebars files are now using my new custom helper. 一切正常,我在grunt任务中引用了帮助文件,运行了“ grunt服务”,瞧,我组装的车把文件现在正在使用新的自定义帮助程序。

However... In my project I also have some handlebars templates files that are not used through Assemble. 但是...在我的项目中,我还有一些把手模板文件,这些文件没有通过Assemble使用。 These templates are being precompiled and used when I eg want to update the product basket on my website, and these web-based templates should also be able to use my custom helpers. 例如,当我想在我的网站上更新产品篮时,这些模板已经过预编译和使用,并且这些基于Web的模板也应该能够使用我的自定义帮助程序。

The code for my handlebars helpers: 我的车把帮手的代码:

module.exports.register = function (Handlebars, options, params) {
  // Helper goes here.
};

How would I go on with RequireJS's amdefine in order to be able to use these helpers in my web-based project. 为了能够在基于Web的项目中使用这些帮助程序,我将如何继续使用RequireJS的amdefine。

Br Dan 布丹

This is a big focus for the v0.6.0 release of handlebars-helpers , you should be able to accomplish what you want with that release. 这是handlebars-helpers v0.6.0发行版的重点,您应该能够使用该发行版完成所需的工作。

There is also an existing issue on that repo to discuss: https://github.com/assemble/handlebars-helpers/issues/36 , feel free to add your thoughts! 该仓库上还有一个现存的问题要讨论: https : //github.com/assemble/handlebars-helpers/issues/36 ,随时添加您的想法!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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