{{>key}}
can.mustache.helpers.partial
{{>key}}
Render another template within the current template.
Parameters
-
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:
- A registered view
- An id of an element
- A url to load the template.
Returns
{String}
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:
base.mustache
user.mustache
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):
The following template uses an absolute path (rooted to steal's root directory):
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:Manually Registering
Partials can be manually registered by calling
can.view.registerView
and passing an identifier and content. For example: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:
then reference the partial in the template just like: