• function


Render another template within the current template.


  1. key {key}

    A key that references a value within the current or parent context. If the value is a function or can.compute, the function's return value is used.

    If the key value is:

    • undefined - the key's name (ex: user.mustache in {{>user.mustache}}) is used to look up a template using can.view.

    • string - the string value is used to lookup a view in can.view.

    • function - the function is called with the current scope.

    can.view looks for a template in the following places:

    1. A registered view
    2. An id of an element
    3. A url to load the template.



The value of the rendered template is inserted into the page.

Partials are templates embedded in other templates. Partials begin with a greater than sign, like {{>my_partial}}. Partials inherit the calling context.

Partials render at runtime, so recursive partials are possible but make sure you avoid infinite loops.

For example, this template and partial:





The resulting expanded template at render time would look like:


Acquiring Partials

Referencing Files

Partials can reference a file path and file name in the template.

The following template uses a relative path (relative to the current page):

<script id="template" type="text/mustache">

The following template uses an absolute path (rooted to steal's root directory):

<script id="template" type="text/mustache">

Referencing by ID

Partials can reference templates that exist in script tags on the page by referencing the id of the partial in the template. For example:

<script id="mytemplate" type="text/mustache">
<script id="mypartial" type="text/mustache">
    I am a partial.
var template = can.view("#mytemplate", {});

Manually Registering

Partials can be manually registered by calling can.view.registerView and passing an identifier and content. For example:

can.view.registerView('myTemplate', "My body lies over {{.}}")

in the template, you reference the template by the identifer you registered:


resulting in the template rendering with the current context applied to the partial.

Passing Partials in Options

Partials can resolve the context object that contains partial identifiers. For example:

var template = can.view("#template", { 
    items: []
    itemsTemplate: "test_template.mustache" 


then reference the partial in the template just like: