monster.template()

This method is used internally to load core templates and should not be used by regular apps.

Syntax

monster.template(thisArg, name[, data, raw, ignoreCache, ignoreSpaces]);

Parameters

KeyDescriptionTypeDefaultRequired
thisArgthis of the app, used for finding the template to load.Objecttrue
nameName of the template, without the file extension.Stringtrue
dataData to pass to the template.Object{}false
rawWhen set to true, Handlebars will not compile the template and it will be sent as is.Booleanfalsefalse
ignoreCacheWhen set to true, request the template even if it was already loaded.Booleanfalsefalse
ignoreSpacesWhen set to true, carriage return, linefeed, tab, whitespace will not be trimmed from the template.Booleanfalsefalse

Description

The monster.template() method allows you to request templates simply by specifying the name of the desired template. You can also pass data to the template with the data parameter.

Examples

Load template with no data into the DOM

function renderApp(container) {
  var template = $(monster.template(app, 'app'));

  container
    .empty
    .append(template);
}

Load template with data into the DOM

function renderApp(container) {
  var userId = app.userId;

  getUserData(userId, function(userData) {
    var dataToTemplate = {
      userId: userId,
      userData: userData
    };
    var template = $(monster.template(app, 'app', dataToTemplate));

    container
        .empty()
        .append(template);
  });
}

Load a string template in a Toastr Notification or Monster Alert

function renderUserCreate(userData) {
  requestCreateUser({
    data: {
      user: userData
    },
    success: function(data) {
      var message = monster.template(app, '!' + app.i18n.active().toastr.success.userCreate, {
        name: data.name
      });

      monster.ui.toast({
        type: 'success',
        message: message
      });
    },
    error: function(data) {
      var message = monster.template(app, '!' + app.i18n.active().alert.error.createUser, {
        type: data.type
      });

      monster.ui.alert('error', message);
    }
  });
}

On this page