Template

ajja.register_template(id, template, description)

Allows you to register your templates or change the default templates.

Arguments:
  • id (string) – The id of the template.
  • template (string|function) – The template. Will be saved as a compiled Handlebars template. Can be a precompiled Handlebars template, the template as raw HTML or the id of a DOM node containing the HTML of the template.
  • description (string) – A description for the template.
Return type:

void

ajja.register_template('my_template', '<dl><dt>{{name}}</dt><dd>{{value}}</dd></dl>');
var form = new ajja.Form('form');
form.load({title: 'Sebastian'}, {title: {template: 'my_template'}});
$('body').append(
    '<script type="text/html" id="reference"><b>{{value}}</b></script>'
);
ajja.register_template('my_template', '#reference');
var form = new ajja.Form('form');
form.load({title: 'Sebastian'}, {title: {template: 'my_template'}});
var compiled = Handlebars.compile('<p>{{value}}</p>');
ajja.register_template('my_template', compiled);
var form = new ajja.Form('form');
form.load({title: 'Sebastian'}, {title: {template: 'my_template'}});
class TemplateHandler()

Helper class for handling templates within ajja.

var handler = new ajja.TemplateHandler();
get_template(id)

Get the template for the given id.

Arguments:
  • id (string) – The id of the template.
Returns:

The template as precompiled Handlebars template.

Return type:

function

handler.get_template('form_boolean')({name: 'asdf'})
'<input type="checkbox" name="asdf" data-bind="checked: asdf" />'
list_templates()

List all registered templates.

Returns:A list of objects containing the id, description and compiled template.
Return type:Array
handler.list_template()[0]
{id: 'form', description: 'The base `ajja.Form` template', template: function}