Show:

Q.Template Class

Module for templates functionality

Constructor

Q.Template

()

Item Index

Methods

Methods

compile

(
  • content
  • [type="handlebars"]
)
Function static

This is used to compile a template once Handlebars is loaded

Parameters:

  • content String

    The content of the template

  • [type="handlebars"] String optional

    The type of the template

Returns:

Function:

a function that can be called to render the template

load

(
  • name
  • callback
  • [options.type='handlebars']
  • [options.dir]
  • [options.name]
)
String | Undefined static

Load template from server and store to cache

Parameters:

  • name String

    The 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

  • callback Function

    Receives two parameters: (err, templateText)

  • [options.type='handlebars'] String optional

    the type and extension of the template

  • [options.dir] String optional

    the folder under project web folder where templates are located

  • [options.name] String optional

    option to override the name of the template

Returns:

String | Undefined:

remove

(
  • name
)
static

Removes a template that may have been set before

Parameters:

  • name String

    The template's name under which it will be found

render

(
  • name
  • fields
  • [callback]
  • [options={}]
)
static

Render template taken from DOM or from file on server with partials

Parameters:

  • name String | Object

    The 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.

  • fields Object

    The fields to pass to the template when rendering it

  • [callback] Function optional

    a callback - receives (error) or (error, html)

  • [options={}] Object optional

    Options for the template engine compiler. Also can include:

    • [type='handlebars'] String optional

      the type and extension of the template

    • [dir] String optional

      the folder under project web folder where templates are located

    • [name] String optional

      option to override the name of the template

    • [tool] String optional

      if the rendered html will be placed inside a tool, pass it here so that its prefix will be used

set

(
  • name
  • content
  • info
)
static

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:

  • name String

    The template's name under which it will be found

  • content String

    The 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.

  • info Object | String

    You can also pass a string "type" here.

    • [type="handlebars"] String optional

      The type of template.

    • [text] Array optional

      Names of sources for text translations, ending in .json or .js

    • [partials] Array optional

      Relative 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 optional

      Relative urls of .js scripts for registering helpers