Handlesbars supports Subexpressions now, so you could just do:
{{i18n (toLowerCase status) }}
(notice, those are parens ()
, not curly braces {}
, for the inside helper)
Pergunta
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 ?
Solução
Handlesbars supports Subexpressions now, so you could just do:
{{i18n (toLowerCase status) }}
(notice, those are parens ()
, not curly braces {}
, for the inside helper)
Outras dicas
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.