Q.Template Class
Module for templates functionality
Constructor
Q.Template
()
Methods
compile
-
content -
[type="handlebars"]
This is used to compile a template once Handlebars is loaded
Parameters:
Returns:
a function that can be called to render the template
load
-
name -
callback -
[options.type='handlebars'] -
[options.dir] -
[options.name]
Load template from server and store to cache
Parameters:
-
nameStringThe template name. Here is how templates are found: First, load any new templates from the DOM found inside script tags with type "text/"+type. Then, check the cache. If not there, we try to load the template from dir+'/'+name+'.'+type
-
callbackFunctionReceives two parameters: (err, templateText)
-
[options.type='handlebars']String optionalthe type and extension of the template
-
[options.dir]String optionalthe folder under project web folder where templates are located
-
[options.name]String optionaloption to override the name of the template
Returns:
remove
-
name
Removes a template that may have been set before
Parameters:
-
nameStringThe template's name under which it will be found
render
-
name -
fields -
[callback] -
[options={}]
Render template taken from DOM or from file on server with partials
Parameters:
-
nameString | ObjectThe name of template (see Q.Template.load). You can also pass an object of {key: name}, and then the callback receives {key: arguments} of what the callback would get.
-
fieldsObjectThe fields to pass to the template when rendering it
-
[callback]Function optionala callback - receives (error) or (error, html)
-
[options={}]Object optionalOptions for the template engine compiler. Also can include:
-
[type='handlebars']String optionalthe type and extension of the template
-
[dir]String optionalthe folder under project web folder where templates are located
-
[name]String optionaloption to override the name of the template
-
[tool]String optionalif the rendered html will be placed inside a tool, pass it here so that its prefix will be used
-
set
-
name -
content -
info
Sets the text and/or info of a template in this document's collection, and compiles it. This is e.g. called by Q.loadUrl when the server sends over some templates, so they won't have to be requested later.
Parameters:
-
nameStringThe template's name under which it will be found
-
contentStringThe content of the template that will be processed by the template engine. To avoid setting the content (so the template will be loaded on demand later), pass undefined here.
-
infoObject | StringYou can also pass a string "type" here.
-
[type="handlebars"]String optionalThe type of template.
-
[text]Array optionalNames of sources for text translations, ending in .json or .js
-
[partials]Array optionalRelative urls of .js scripts for registering partials. Can also be names of templates for partials (in which case they shouldn't end in .js)
-
[helpers]Array optionalRelative urls of .js scripts for registering helpers
-