• function

{{data name}} can.Mustache.helpers.data

 

{{data name}}

Adds the current context to the element's can.data.

Parameters

  1. name {String}

    The name of the data attribute to use for the context.

Use

Its common you want some data in the template to be available on an element. {{data name}} allows you to save the context so it can later be retrieved by can.data or $.fn.data. For example,

The template:

<ul>
  <li id="person" {{data 'person'}}>{{name}}</li>
</ul>

Rendered with:

document.body.appendChild(
  can.view.mustache(template,{ person: { name: 'Austin' } });

Retrieve the person data back with:

$("#person").data("person")