Template Class
Provides a generic API for using template engines such as Handlebars and
Y.Template.Micro
.
Examples
Using with Y.Template.Micro
(the default template engine):
YUI().use('template', function (Y) {
var micro = new Y.Template(),
html = micro.render('<%= data.message %>', {message: 'hello!'});
// ...
});
Using with Handlebars:
YUI().use('template-base', 'handlebars', function (Y) {
var handlebars = new Y.Template(Y.Handlebars),
html = handlebars.render('{{message}}', {message: 'hello!'});
// ...
});
Constructor
Template
-
[engine=Y.Template.Micro]
Parameters:
-
[engine=Y.Template.Micro]
Mixed optionalTemplate engine to use, such as
Y.Template.Micro
orY.Handlebars
. Defaults toY.Template.Micro
if not specified.
Methods
compile
-
text
-
[options]
Compiles a template with the current template engine and returns a compiled template function.
Parameters:
Returns:
precompile
-
text
-
[options]
Precompiles a template with the current template engine and returns a string containing JavaScript source code for the precompiled template.
Parameters:
Returns:
render
-
text
-
data
-
[options]
Compiles and renders a template with the current template engine in a single step, and returns the rendered result.
Parameters:
Returns:
revive
-
precompiled
-
[options]
Revives a precompiled template function into an executable template function using the current template engine. The precompiled code must already have been evaluated; this method won't evaluate it for you.
Parameters:
Returns:
Properties
engine
Mixed
Template engine class.