Webanizr Logo
Open / sluit menu
Module showTemplate

Last change: July 2, 2020

Current version: 1.6.1

he showTemplate module uses an html template element to display data. The html from the template element is rendered with mustache and then added to the given html destination element.

syntax

webanizr.send('showTemplate', data, parameters, callback);

data

The data to use when parsing the data. When the following data is received:

{
    firstname__person : "John",
    email__person : "john@whereismyemail.com"
}

It can be used in a template:

<template id="mytemplate">
    <p>Hello {{ firstname__person }}, your email address is {{ email__person }}.</p>
</template>

Which will result in:

Hello John, your email address is john@whereismyemail.com.

parameters

The showTemplate accepts the following parameters:

id__dom (required)

The html id of the element to which to add the rendered html from the template.

id__template (required)

The html id of the template containing the html that should be rendered.

mode__decode (optional)

Lets the module decode the given content before running it through mustache. The options for this parameter are:

  • none: do note decode (default)
  • webanizr: use webanizr decoding
  • vars: replace Webanizr vars: {name__var}

type__placement (optional)

Tells the module how to add the generated html to the dom element. Te options for this parameter are:

  • replace: replace the current content with the generated html (default)
  • add: ad the html to the current content

function__check (option)

Function to check if the template has been rendered yet. The function has 5 tries, 300 miliseconds apart. If the template has not been rendered then, a log event is triggered. The function should return false if the template is not loaded far enough and true if the template has been rendered. The callback function will not be called untill the check function returns true.

callback

The callback is called with the original data.

demos

https://cdn.cpmodules.webanizr.com/demo/display-data-in-template/index.html

https://cdn.cpmodules.webanizr.com/demo/display-product-list/index.html

changelog

  • July 2, 2020: 1.6.1 - Non html escaped mustache vars (triple {) now work correct
  • April 17, 2020: 1.6.0 - Id__dom can now also be the element itself instead of an id of the element
  • February 17, 2020: 1.5.0 - Added suppport for mode__decode "vars" option
  • November 18, 2019: 1.4.0 - Added the check function parameter
  • October 7, 2019: 1.3.2 - Removed console.log that was left from testing
  • October 3, 2019: 1.3.1 - Translation is now done before the Mustacte parsing
  • October 3, 2019: 1.3.0 - Support for translations using the %% syntax