3

I have written two helpers namely i18n and toLowerCase as following:

/*
* Returns lowercase of a string
*/
Handlebars.registerHelper('toLowerCase', function(value) {
  if (value && typeof value === 'string') {
    return value.toLowerCase();
  } else {
    return '';
  }
});

I have a string which should be converted to lowercase first and then should be localized using i18n helper. Both these helpers work/run fine.

These lines are working fine. (Tested)

{{toLowerCase status }}
{{i18n status}}

But I want something like this.I have tried this:

{{i18n {{toLowerCase status }} }}

But this throws syntax error as Uncaught Error: Parse error on line 88:

..div>      {{ i18n  {{toLowerCase stat
----------------------^
Expecting 'CLOSE', 'CLOSE_UNESCAPED', 'STRING', 'INTEGER', 'BOOLEAN', 'ID', 'DATA', 'SEP', got 'OPEN' 

Any suggestions ?

Sachin Jain
  • 21,353
  • 33
  • 103
  • 168
  • Similar SO question: http://stackoverflow.com/questions/14781916/is-it-possible-with-handlebars-to-nested-helpers-inside-the-options-hash – tsiki Aug 12 '13 at 12:48

2 Answers2

4

Handlesbars supports Subexpressions now, so you could just do:

{{i18n (toLowerCase status) }}

(notice, those are parens (), not curly braces {}, for the inside helper)

Firo
  • 15,448
  • 3
  • 54
  • 74
1

You could try using https://github.com/mateusmaso/handlebars.nested (be aware that it allows only one level of nesting, though). As far as I know, there's no built-in support on Handlebars for this, though you can use some of the workarounds in the question I linked in comments.

tsiki
  • 1,638
  • 21
  • 34