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]+ +
+
+ -
+
+
[defaults]+ +
+
+
Parameters:
+ +-
+
+
-
+
+
[engine=Y.Template.Micro]+ Mixed + optional + + + + +++ + +Template engine to use, such as +
+Y.Template.MicroorY.Handlebars. Defaults toY.Template.Microif not + specified.
+
+ -
+
+
[defaults]+ Object + optional + + + + +++ + +Default options to use when instance methods are + invoked.
+
+
+
-
+
- Index + + +
- Methods + + +
- Properties + + + +
Item Index
+ + +Methods
+ +-
+
+
- + compile + + + + + +
- + precompile + + + + + +
- + render + + + + + +
- + revive + + + + + +
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:
+ +-
+
+
-
+
+
text+ String + + + + +++ + +Template text to render.
+
+
+ -
+
+
data+ Object + + + + +++ + +Data object to provide when rendering the template.
+
+
+ -
+
+
[options]+ Object + optional + + + + +++ + +Options to pass along to the template engine. See + template engine docs for options supported by each engine.
+
+
+
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.
+