How do I lowercase a field using Handlebars.js?

前端 未结 5 1157
我寻月下人不归
我寻月下人不归 2021-02-01 14:27

I want to do something like this:

{{user.name.toLowerCase()}}

but I get this error:

Error: Parse error on line X:
...tatus {{us         


        
5条回答
  •  天命终不由人
    2021-02-01 14:49

    Previous answer from @Eric seems not to work now, my solution is very similar, but probably the definition of helpers changed a little in new versions of handlebars:

    Handlebars.registerHelper('tolower', function(options) {
        return options.fn(this).toLowerCase();
    });
    

    and in the template

    Cheers

提交回复
热议问题