BorisMoore / jsrender

A lightweight, powerful and highly extensible templating engine. In the browser or on Node.js, with or without jQuery.

Home Page:http://www.jsviews.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

how to use with dotted variable names

rakucmr opened this issue · comments

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"
};

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>

Thanks, this is working!