Search code examples
jsrender

JS Render interpreting hyphen in property name as subtraction sign


I'm using JS Render to iterate over some data which uses hyphens in property names.

{{:image_one.sizes.natural-massive}}

That is returning a NAN result because it's attempting to run a mathematical operation. How can I force JS render to treat that as a string?


Solution

  • You can use brackets as property accessor.

    See the docs for path notation: Using the 'bracket' property accessor: object["property"]

    In your case, you can write:

    {{:image_one.sizes["natural-massive"]}}