Pass someVar+'a string' to Handlebars.js helper?

Kristoffer K picture Kristoffer K · Jul 1, 2013 · Viewed 7.6k times · Source

Let's say I have this Handlebars helper:

Handlebars.registerHelper('someRandomHelperCreatingALink', function(passedVarAndString, url) {
    return '<a href="'+url+'">'+passedVarAndString+'</a>';
});

And want to use it like this, where I pass both a string AND a var as the first argument (user.name+' is a cool dude!'):

{{{ someRandomHelperCreatingALink user.name+' is a cool dude!!' '/a/cool/url' }}}

My question: Would that somehow be possible?

Or do I have to add an extra argument for the string (which would feel unnecessary)? Something like this:

Handlebars.registerHelper('someRandomHelperCreatingALink', function(passedVarAndString, url, extraUnnecessary) {
    return '<a href="'+url+'">'+passedVarAndString+extraUnnecessary+'</a>';
});

{{{ someRandomHelperCreatingALink user.name '/a/cool/url' ' is a cool dude!!' }}}

Answer

CarolineBda picture CarolineBda · Feb 5, 2015

This is not possible because at this point the parameter is just a string. You can either create a second helper to concatenate the strings, either build the string before in a controller