express-hbs instance registerAsyncHelper weird hash

﹥>﹥吖頭↗ 提交于 2019-12-10 16:59:39

问题


I'm using express-hbs nodejs module and I have an issue using registerAsyncHelper. I need compile a layout in restrict scope because of this I've created a new Handlebars instance and I've created a helper in this instance. But when I compile the layout it returns a weird hash. My code is something like this:

var hbs = require('express-hbs');
var hbs_temp = hbs.create();

hbs_temp.registerAsyncHelper( 'content', function( text, cb ) {     
    fs.readFile( 'some-file', { encoding: 'utf8' }, function( err, data ) {
        cb( new hbs_temp.SafeString( data ) );
    });
});

hbs_temp.compile( '<div> {{content}} </div>' )(  );`

Result:

<div> __WEIRD HASH__ </div>

My question is. I've something wrong in my code or this is a "express-hbs" bug? Thank you!


回答1:


The express-hbs module inserts those hashes in place of asynchronously returned values, and replaces them when the async calls have completed. You must use it in the context of Express, as a rendering engine to see this working.



来源:https://stackoverflow.com/questions/23546427/express-hbs-instance-registerasynchelper-weird-hash

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!