Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

access object property in handlebar contains '.'

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 vanilla JavaScript we can access it like this['s.no'] but in handlebars it's not working.

like image 642
Inderjeet Singh Ahuja Avatar asked Sep 12 '25 03:09

Inderjeet Singh Ahuja


1 Answers

You need to use special [] notation for properties that are not valid handlebar identifiers. Demo.

{{#each this}}
   <div>
      <span>{{this.[s.no]}}</span>
      <h2>{{this.title}}</h2>
   </div>
{{/each}}
like image 104
Yury Tarabanko Avatar answered Sep 14 '25 18:09

Yury Tarabanko