this and . : The Current Item
Inside a loop or with block, this - or a leading . - refers to the current item.
Syntax
{{this}}
{{this.property}}
{{.property}}
{{.}}
Examples
Data:
builder.WithData("model", new {
tags = new[] { "urgent", "finance" },
items = new[] {
new { name = "Widget", price = 10.0 },
new { name = "Gadget", price = 15.5 }
}
});
Template:
{{#each model.tags}}
<span>{{this}}</span>
{{/each}}
{{#each model.items}}
<p>{{this.name}} - {{.price}}</p>
{{/each}}
Output:
urgent finance
Widget - 10
Gadget - 15.5
Notes
this.nameand.nameare the same.- A plain name is also looked up on the current item, so inside a loop
{{name}}usually works too.thismakes it clear, and avoids a clash with a data name of the same name. - Outside any loop or
withblock,thisis the document’s data.