handlebars-lang / handlebars.js

Minimal templating on steroids.
http://handlebarsjs.com
MIT License
17.96k stars 2.04k forks source link

access object property in handlebar contains '.' #1329

Closed isahuja closed 7 years ago

isahuja commented 7 years ago

Before filing issues, please check the following points first:

This will probably help you to get a solution faster. For bugs, it would be great to have a PR with a failing test-case.

isahuja commented 7 years ago

I am getting data from service in which array of objects are coming like below:-

[{
    title : 'Tilte 1',
    s.no : 1
 },
 {
    title : 'Tilte 2',
    s.no : 2   
 }
]

I have used handlebars templating to parse this data like below:-

{{#each this}}
   <div>
      <span>{{this.s.no}}</span>
      <h2>{{this.title}}</h2>
   </div>
{{/each}}

In the above I am not able to access the property('s.no'). In vanila javascript we can access it like this['s.no'] but in handlebars it's not working.

Thanks in advance

nknapp commented 7 years ago

{{this.[s.no]}} should work. Have a look a the http://handlebarsjs.com/expressions.html for the details.

https://jsfiddle.net/vva7musq/14/ for an example

isahuja commented 7 years ago

@nknapp Thanks, it's working.