public interface StringTemplateFunctions state object plus a shared support object sc, and optionally j, which is the default JSON formatter function. sc and j are described below. Templates are registered on a class using Class.registerTemplates() and later rendered with Class.render().
OrderViewer.registerTemplates({
orderSummaryHTML: function (s, sc, j) {
return `<b>Order #${s.orderId}</b><br>
Customer: ${sc.escapeHTML(sc.trim(s.customerName))}<br>
Status: ${s.status}<br>
Total: ${sc.toUSCurrencyString(s.totalAmount, 2)}<br>
`;
},
lineItemsHTML: function (s, sc, j) {
return sc.if(s.items && s.items.length > 0,
"Line Items:<br>" + sc.for(s.items, function (item) {
return ` - ${item.quantity} x ${sc.escapeHTML(item.description)} (${sc.NumberUtil.toUSCurrencyString(item.price, 2)})<br>`;
}),
"No items on this order."
);
}
});
Render a template from an instance:
const orderSummaryHTML = orderViewer.render("orderSummaryHTML", {
orderId: 10234,
customerName: " Smith, John ",
status: "Pending",
totalAmount: 259.99
});
const orderLineItemsHTML = orderViewer.render("lineItemsHTML", {
items: [
{ quantity: 2, description: "Widget A", price: 49.95 },
{ quantity: 1, description: "Service Plan", price: 160.09 }
]
});
sc)sc parameter providing shared utilities: JSONEncoder. If pretty is true, the output is formatted with indentation.thenVal if true, otherwise elseVal.null, returns an empty string.null, returns an empty string. The sc object also inherits from the global com.smartgwt.client.util.isc object (through prototypal inheritance), so all Smart GWT APIs are available (for example, sc.NumberUtil references the NumberUtil class).