Dash character in Spacebars

Hey,

is there a way to refer to a field containing a dash character (-) ?

e.g., I have some object in the data context:

foo = { 'bar-1': 5}

and I’d like to use it in a template:

<template name="aTemplate">
...
<a some-attribute="{{foo.bar-1}}"></a>

this of course wouldn’t work.
I went through Spacebars’ docs again and couldn’t find the right syntax (if there is one)

Thanks

There is a way to do this:

<a some-attribute="{{foo.[bar-1]}}"></a>

Note the lack of quotes and the extra dot before the square brackets (the equivalent in JS would be foo['bar-1'])

1 Like