External component with Handlerbars.js integration

Integration with third-party UI libraries is possible due to the flexibility of the external component.

The following example uses the Handlebars.js library to display information about an asset through the external component.

Configuration tab

Code tab

The code illustrates the initialization of a simple Handlebars.js component. Its instance subscribes to the entityLoaded event. When the entity loads, the required information maps to our component. On every entity saved, the entitySaved event triggers to update the information.

In this example, we use the following code:

var source   = document.getElementById("entry-template").innerHTML;
var template = Handlebars.compile(source);

var entityLoadedSubscription = options.mediator.subscribe("entityLoaded", function (entity) {
    var entitySavedEvent = Utils.format("entitySaved:{id}", { id: entity.systemProperties.id() });
    options._page.mediator.subscribe(entitySavedEvent, updateUI);

function updateUI(entity){
    var title = entity.properties.Title();
    var description = entity.properties.Description()[options.culture];
    var context = {title: title, description: description};
    var html    = template(context);
    document.getElementById("handlebars-result-container").innerHTML = html;

Template tab

Our external component code requires the following HTML markup:

<template class="entry" id="entry-template" type="text/x-handlebars-template">
    <div class="body">
  <div id="handlebars-result-container">

End result

After saving the changes, we navigate to an Asset details page. Our external component is displayed:

Can we improve this article ? Provide feedback