Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Square braces in key name #1092

Closed
distantnative opened this issue Sep 7, 2015 · 6 comments
Closed

Square braces in key name #1092

distantnative opened this issue Sep 7, 2015 · 6 comments
Labels

Comments

@distantnative
Copy link

I have the following data structure:

[Log] [ (panel, line 126)
Object
countries[]: Array[2]
    0: "de"
    1: "en"
rate: "3 %"
]

And would like to output it with:

{{rate}}: {{countries[]}}

Sadly, this isn't working. The square brackets in the key name countries[] seem to be the problem. They get created by the CMS. If I remove them manually, {{rate}}: {{countries}} works. Any idea how to make it work with the square brackets in the key?

@BenjaminHorn
Copy link

I can not see any difference between your "working" and "not working" example.
What is the desired result?

@distantnative
Copy link
Author

Sorry, the working example should be without the brackets: {{rate}}: {{countries}} (edit above). This works after manually changing the data structure to

[Log] [ (panel, line 126)
Object
countries: Array[2]
    0: "de"
    1: "en"
rate: "3 %"
]

(countries key without brackets)

But since the CMS usually gives me that array with countries[] as key, I would be happy to find a working way to get this working as well.

{{rate}}: {{countries[]}} throws the following error:

[Error] Error: Parse error on line 12:
...        {{rate}}: {{countries[]}}      <
-----------------------^
Expecting 'ID', 'DATA', got 'INVALID'

@kpdecker kpdecker added the bug label Sep 7, 2015
@kpdecker
Copy link
Collaborator

kpdecker commented Sep 7, 2015

[] is used for ID lookups so this is being parsed as a language operator. For values in the first position you can do {{"foo[]"}} and it will lookup the value. This will not work for arguments to helpers though. We need to allow for some sort of escaping of these values, or alternatively treat them as part of the ID when not in the leading position.

@kpdecker
Copy link
Collaborator

Released in 4.0.3

@wojcikstefan
Copy link

@kpdecker unless I'm missing something, this still doesn't work. Consider the example that you use in 0878179 for the tokenization unit test: 0878179#diff-03f34a34f3e0cca43f4403093688e205R150

Trying it out via http://tryhandlebarsjs.com/ fails:

screen shot 2017-01-17 at 3 21 33 pm

@trieu-hphuc96
Copy link

I stuck at here too, Is there another way? It doesn't work. Thanks in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants