{{key}}

  • function
can.mustache.tags.escaped  

Insert the value of the key into the output of the template.

{{key}}

Parameters

  1. key {key}

    A key that references one of the following:

Returns

{String | function() | *}

After the key's value is found (and set to any function's return value), it is passed to can.view.txt as the result of a call to its func argument. There, if the value is a:

  • null or undefined - an empty string is inserted into the rendered template result.
  • String or Number - the value is inserted into the rendered template result.
  • Function - A hookup attribute or element is inserted so this function will be called back with the DOM element after it is created.

Use

{{key}} insert data into the template. It most commonly references values within the current context. For example:

Rendering:

<h1>{{name}}</h1>

With:

{name: "Austin"}

Results in:

<h1>Austin</h1>

If the key value is a String or Number, it is inserted into the template. If it is null or undefined, nothing is added to the template.

Nested Properties

Mustache supports nested paths, making it possible to look up properties nested deep inside the current context. For example:

Rendering:

<h1>{{book.author}}</h1>

With:

{
  book: {
    author: "Ernest Hemingway"
  }
}

Results in:

<h1>Ernest Hemingway</h1>

Looking up values in parent contexts

Sections and block helpers can create their own contexts. If a key's value is not found in the current context, it will look up the key's value in parent contexts. For example:

Rendering:

{{#chapters}}
   <li>{{title}} - {{name}}</li>
{{/chapters}}

With:

{
  title: "The Book of Bitovi"
  chapters: [{name: "Breakdown"}]
}

Results in:

<li>The Book of Bitovi - Breakdown</li>