SFRA Server-side Javascript - Source: app_storefront_base/cartridge/scripts/renderTemplateHelper.js menu

SFRA / Server-side JS / Source: app_storefront_base/cartridge/scripts/renderTemplateHelper.js

'use strict';

var HashMap = require('dw/util/HashMap');
var Template = require('dw/util/Template');

/**
 * gets the render html for the given isml template
 * @param {Object} templateContext - object that will fill template placeholders
 * @param {string} templateName - the name of the isml template to render.
 * @returns {string} the rendered isml.
 */
function getRenderedHtml(templateContext, templateName) {
    var context = new HashMap();

    Object.keys(templateContext).forEach(function (key) {
        context.put(key, templateContext[key]);
    });

    var template = new Template(templateName);
    return template.render(context).text;
}

module.exports = {
    getRenderedHtml: getRenderedHtml
};