All Things IoT | Losant Blog

Master Losant's Template Engine with the Template Tester

Written by Heath Blandford | Wed, Nov 11, 2020

The Losant Template Tester is an interactive tool that provides a means for users to practice, test, and explore examples of templates and helpers using Losant's Template Engine. As payloads, context, and templates get more complex, developers need to quickly see and debug the results of their templates. This is the goal of the Template Tester.

Alongside Losant’s educational tools like the Workflow Lab and Losant University, the Template Tester is intended to be used by both new and experienced Losant Developers to learn, use, test, debug, and master Losant's Template Engine. Losant's Template Engine is the primary way for Losant Developers to access payload data in the Visual Workflow Engine and access context from Render Logs while building End-User Experiences.

What is Templating?

Templating in Losant is an extension of Handlebars and is the primary way to access payload data in the Visual Workflow Engine and access context while building End-User Experiences. When the template is executed, these expressions are replaced with values from an input object. Templates follow the formatting of {{data.value}}

For some Losant Developers, “templates” may be an age-old term, but the Template Tester allows both new and experienced Losant Developers to practice and test templates with example context or payloads from their own applications.

Template Engines are designed to combine templates with a data model to produce result documents.

In Losant, the data model is a payload or context. For example:

{
  "data": {
    "hello": "world"
  }
}

Assume that, in a workflow, you want to provide the value “world” to a String Node to manipulate that string. To do that, you provide the following template to the String Node in a workflow:

{{data.hello}}

When the Workflow runs, the String Node renders the template and uses its result, which in this example is:

world

How does the Template Tester Work?

The Template Tester tool contains three sections:

  • Context: Field where you input your template context. You can create your own or you can copy/paste context directly from a workflow's Debug Panel and an experience's Render Log.
  • Template: Field where you input your template, such as,  {{data.value}} . This field uses the same tools as the Losant Platform and has full access to all of Losant’s helpers that offer additional capability beyond the built-in Handlebars helpers.
  • Result: Displays the output based on the values in the previous two fields.

Since the Template Tester uses the same tools used in the Losant Platform, all of your work can be moved back into Losant so you can continue to build your workflow or experience.

Sharing a Template

While building templates, you may want to share these examples with other members in your Losant Organization. Using the Template Tester, you can share any Context/Template pair you make by clicking the “Copy URL to Clipboard” button under the Share this Template section.

This button creates a shareable URL and places it on your clipboard.

Getting Started

The Template Tester can help you and your team gain a better understanding of templates and how to access data in more complex contexts. This can help you be more effective in building your own workflows as you create IoT applications.

Try the Template Tester for yourself in the Losant Developer Sandbox.