dot.js working with array

273 views Asked by At

I have a problem working with dot when I have template like this

{{=it.data[0].visitors}}

so this doesn't work

var data = [{
  visitors: 10
}];

var tempFn = doT.template("<h1>Here is a sample template {{=it.data[0].visitors}}</h1>");

var resultText = tempFn(data[0]);
1

There are 1 answers

1
Jayffe On

You need to name what you insert as template vars :

http://jsfiddle.net/0ds9rfk1/

var tempFn = doT.template("<h1>Here is a sample template {{=it.data.visitors}}</h1>");
var resultText = tempFn({data:data[0]});

or

var tempFn = doT.template("<h1>Here is a sample template {{=it.data[0].visitors}}</h1>");
var resultText = tempFn({data});