mozilla / nunjucks

A powerful templating engine with inheritance, asynchronous control, and more (jinja2 inspired)
https://mozilla.github.io/nunjucks/
BSD 2-Clause "Simplified" License
8.48k stars 635 forks source link

Variable with minus sign. #1379

Open amar1995 opened 2 years ago

amar1995 commented 2 years ago

Example of sample.json:

{ "file-1": "my_file_1" }

How can I get value when the key contains a minus sign?

I try that {{ file-1 }}, {{ "file-1" }} and {{ ["file-1"] }} but it doesn't works. I am getting value NaN. I don't want to change the key name, can anyone guide me on how to do it using nunjucks.

fspoettel commented 2 years ago

See here for a related discussion and workarounds. This is in the context of eleventy but the general idea should be applicable to any nunjucks project.