I have following data in json
"ICON":{
"144":".jpg",
"228":".jpg",
"72":".jpg",
"152":".jpg",
"130":".jpg",
"120":".jpg",
"32":".jpg"
}
In handlebars, I am trying to access property 32
like following.
<img src="{{ ICON.32 }}">
and I get following error
Module build failed: Error: Parse error on line 5:
..."{{ mediaFiles.ICON.32 }}"> <sp
-----------------------^
Expecting 'ID', got 'NUMBER'
How can I solve this problem?
I have following data in json
"ICON":{
"144":"https://example./bubble-academy.jpg",
"228":"https://example./bubble-academy.jpg",
"72":"https://example./bubble-academy.jpg",
"152":"https://example./bubble-academy.jpg",
"130":"https://example./bubble-academy.jpg",
"120":"https://example./bubble-academy.jpg",
"32":"https://example./bubble-academy.jpg"
}
In handlebars, I am trying to access property 32
like following.
<img src="{{ ICON.32 }}">
and I get following error
Module build failed: Error: Parse error on line 5:
..."{{ mediaFiles.ICON.32 }}"> <sp
-----------------------^
Expecting 'ID', got 'NUMBER'
How can I solve this problem?
Share Improve this question edited Jan 7, 2017 at 17:17 Felix Kling 817k181 gold badges1.1k silver badges1.2k bronze badges asked Jan 7, 2017 at 17:15 Om3gaOm3ga 33k45 gold badges149 silver badges230 bronze badges 7-
5
Not knowing handlbars, I guess
{{ ICON[32] }}
? edit: Ah, should beICON.[32]
. Docs: handlebarsjs./expressions.html – Felix Kling Commented Jan 7, 2017 at 17:17 -
1
with
ICON.[32]
, it worked. – Om3ga Commented Jan 7, 2017 at 17:20 - 1 Uriel was right, unfortunately they deleted their answer :-/ – Felix Kling Commented Jan 7, 2017 at 17:21
- 1 What's the lesson learned here for everybody? Always read the documentation. – Felix Kling Commented Jan 7, 2017 at 17:21
- 1 Almost a duplicate of How do I access an access array item by index in handlebars? – Felix Kling Commented Jan 7, 2017 at 17:25
2 Answers
Reset to default 6This is because you are using a number as the property name, try using this instead:
<img src="{{ ICON.[32] }}">
Here is also an interesting case to confuse people: (this is how statically generated wordpress forms look)
Input
{
"body" : {
'input_2.2': 'Mrs.',
'input_2.3': 'Cynthia',
'input_2.6': 'Winterbottom',
'input_6': 'Professor',
}
}
This template results in blanks
<p>Form submission</p>
<p>{{body.input_2.[2]}} {{body.input_2.[3]}} {{body.input_2.[6]}}</p>
<p>{{body.input_6}}</p>
Result:
<p></p>
<p>Professor</p>
Apparently since all of the numeric entries do not exist... you can not simply bracket them... you must group the whole subpath at once
Proper template:
<p>Form submission</p>
<p>{{body.[input_2.2]}} {{body.[input_2.3]}} {{body.[input_2.6]}}</p>
<p>{{body.input_6}}</p>
This was found via trial and error... could not find proper documentation explaining this