You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the following example, options.fn() returns a promise instead of a string.
varpromisedHandlebars=require('../')varQ=require('q')varHandlebars=promisedHandlebars(require('handlebars'))// Register a helper that returns a promise for a booleanHandlebars.registerHelper('eventually-true',function(){returnQ.delay(100).then(function(){returntrue})})// Trim whitespaces from block-content result.Handlebars.registerHelper('trim',function(options){returnoptions.fn().trim();});vartemplate=Handlebars.compile('{{#trim}}{{#if (eventually-true)}} abc{{/if}}{{/trim}}')// The whole compiled function returns a promise as welltemplate({}).done(console.log)
The if-helper returns a promise because it has a promise as argument. This promise has a toString()-method that creates a placeholder, but it does not have a .trim() method.
The text was updated successfully, but these errors were encountered:
The solution would be to check if the helper is used as a block helper and then convert the return value to a string in the helper wrapper.
This implies the assumption that block-helpers can never be used in other helpers arguments (which is probably true).
However, simple helpers must be able to return promises, which can be seen in the same example.
In the following example,
options.fn()
returns a promise instead of a string.The
if
-helper returns a promise because it has a promise as argument. This promise has atoString()
-method that creates a placeholder, but it does not have a.trim()
method.The text was updated successfully, but these errors were encountered: