render
can.view.render
Render a template.
can.view.render(template[, callback])
Parameters
-
view
{String | Object}
The path of the view template or a view object.
-
callback
{function()}
OptionalA function executed after the template has been processed.
Returns
{function() | can.Deferred}
A renderer function to be called with data and helpers or a Deferred that resolves to a renderer function.
can.view.render(template, data[, [helpers,] callback])
Parameters
-
view
{String | Object}
The path of the view template or a view object.
-
data
{Object}
OptionalThe data to populate the template with.
-
helpers
{Object<String,function()>}
OptionalHelper methods referenced in the template.
-
callback
{function()}
OptionalA function executed after the template has been processed.
Returns
{String | can.Deferred}
The template with interpolated data in string form or a Deferred that resolves to the template with interpolated data.
can.view.render(view, data, [helpers], callback)
returns the rendered markup produced by the corresponding template engine as String. If you pass a deferred object in as data, render returns a deferred resolving to the rendered markup.can.view.render
is commonly used for sub-templates.Example
welcome.ejs looks like:
Render it to a string like:
Use as a Subtemplate
If you have a template like:
Using renderer functions
If you only pass the view path, `can.view will return a renderer function that can be called with the data to render: