Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reference an element with spaces in handlebars on node.js?

I have an object in witch some of the values are strings containing spaces. Something like this:

object = {
 "group of people": [
  {
   (...)
  }
 ],
 "another group of people": [
  {
   (...)
  }
 ]
}

And I'm trying to use it with the handlebars helper block in my view (index.hbs) like this:

{{#each group of people}}
 (...)
{{/each}}

But I get an error (of course), because of the spaces on "group of people". I've tried the following cases without any success:

{{#each "group of people"}}
{{#each 'group of people'}}
{{#each group%20of%20people}}
{{#each groupofpeople}}
{{#each group of people}}

Any idea on how to get this working?

like image 644
Diogo Capela Avatar asked Nov 30 '25 11:11

Diogo Capela


1 Answers

To use a property that has spaces, you can decorate it with []. e.g. Given helpers:

obj = {
  'property with spaces': 'hello'
};

Template:

<p>{{[property with spaces]}}</p>

Would generate:

<p>hello</p>
like image 186
bsyk Avatar answered Dec 01 '25 23:12

bsyk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!