Read control nodes and generate HTML text

Widget used
Functions covered
Composition structure
Composition script
Singular control app
Last updated

Last updated
(function() {
const HTML_TEMPLATE = "<html>{{firstname}} <b>{{lastname}}</b></html>";
return {
init: function(comp, context) {
// get reference to the fullname widget
const wiLowerFullname = comp.findWidget("lowerFullname")[0];
/**********************************************************************/
// we define a function to update the composition
function updateComposition() {
// get control node payload as JSON object
const p = comp.getPayload2();
console.log(p);
// build HTML text.
let htmlFullname = HTML_TEMPLATE.replace("{{firstname}}", p["Firstname"]);
htmlFullname = htmlFullname.replace("{{lastname}}", p["Lastname"]);
// update fullname text
wiLowerFullname.setPayload({
"text": htmlFullname
});
}
/**********************************************************************/
// we listen to payload_changed events
comp.addListener('payload_changed', (event, msg, e) => {
updateComposition();
e.stopPropagation();
});
/**********************************************************************/
// update the composition when loading the output URL
updateComposition();
},
close: function(comp, context) {}
};
})();