Search code examples
jsrender

jsrender: how to include write space in jsrender expression


if i have data as such: {My name: "Pete"}

and {{:My name}} gives me undefined value. Is there way to escape white space in expression? Please note i cannot change key ("My Name") to something contains no white space in given data.

Thanks


Solution

  • If you really need to have javascript objects (or JSON) with property names that include white-space (but this is best avoided if at all possible), then you can do so by writing:

    Data:

    {"My name": "Pete"}
    

    Template

    {{:#data["My name"]}}
    

    #data is the current data. See http://www.jsviews.com/#paths and http://www.jsviews.com/#views