can.Mustache
can.MustacheConstructor 1.1Deprecated 2.1
As of 2.1, this is considered an internal API. Use can.mustache to create templates.
Logic-less mustache templates with live binding when used with can.Maps.
new can.Mustache(options)
Creates an instance of a mustache template. This is typically not used directly in favor of can.view or can.mustache.
Parameters
-
options
{Object}
An options object with the following properties:
{{{key}}}
Behaves just like {{key}} and {{helper}} but does not escape the result.
{{&key}}
The {{&key}} tag is an alias for {{{key}}}, behaving just like {{key}} and {{helper}} but does not escape the result.
{{#key}}BLOCK{{/key}}
Render blocks of text one or more times, depending on the value of the key in the current context.
{{/key}}
Ends a {{#key}} or {{#helper}} block.
{{^key}}BLOCK{{/key}}
Render blocks of text if the value of the key is falsey.
{{>key}}
Render another template within the current template.
{{!key}}
The comment tag operates similarly to a <!-- --> tag in HTML.
Use
Mustache and Handlebar templates are compatible with can.mustache.
Mustache templates looks similar to normal HTML except they contain keys for inserting data into the template and sections to enumerate and/or filter the enclosed template blocks.
For example, the following renders a welcome header for a user and displays the number of messages.
Mustache Template
JavaScript
HTML Result
To update the html using live-binding, change an observable value:
This updates this paragraph in the HTML Result to:
can.mustache provides significantly more functionality such as:
Tags