BorisMoore / jsrender

A lightweight, powerful and highly extensible templating engine. In the browser or on Node.js, with or without jQuery.
http://www.jsviews.com
MIT License
2.67k stars 339 forks source link

how to use with dotted variable names #349

Closed rakucmr closed 5 years ago

rakucmr commented 5 years ago

How can I use with variables name that have a dot inside, like this:

<script id="theTmpl" type="text/x-jsrender">
{{:product.name}} - {{:product.price}}
</script>

<script>
var data = {
  "product.name": "Product Name",
  "product.price": "$ 100"
};
BorisMoore commented 5 years ago

You can use bracket notation, just as with regular JavaScript. I'll add the following example to the docs to illustate that. Once published it will be at: www.jsviews.com/#paths@bracketnotation

data = {
  "first name": "Jo",
   "address": {
      "1stLine": "My Place",
      "street.name": "Broadway"
    }
 }
<script id="myTmpl" type="text/x-jsrender">
  {{:#data["first name"]}} lives at
  <em>
    {{>address['1stLine']}}
    {{>~root["address"]["street.name"]}}
  </em>
</script>
rakucmr commented 5 years ago

Thanks, this is working!