Handlebars triple stache inside of a double stache

486 views Asked by At

I have registered a handlebars helper by the name of "t" that will translate a string. I have a Handlebars template which uses the value of a variable that will be a word:

{{{word}}}

I would like to translate the value of that variable using my helper, but cannot do

{{t "{{{word}}}" }}   or   {{t {{{word}}} }}

I am inexperienced with Handlebars and am wondering - What is the simplest way to achieve this?

1

There are 1 answers

0
gfullam On

{{t word}}

Simply pass the reference into your helper without brackets.

You only need brackets for outputting the value of the reference to the page:

Handlebars HTML-escapes values returned by a {{expression}}. If you don't want Handlebars to escape a value, use the "triple-stash", {{{.

UPDATE:

If you need to perform some kind of operation (such as escaping HTML) on the value of word, you can make a second helper and pass that into your first helper using ( parentheses ):

{{t (myOtherHelper word)}}