Im trying to use a template literal on a value coming from the database, this values is saved like below
{
"classical" : "cs",
"state" : "myState",
"template" : "this is ${countryName} <b>Thanks for ${departmentName}</>"
}
this is how it is saved in my database. Now during my business logic i read this record and get the template value and save it to a variable. I want to replace {countryName} and with some value coming from data.
I have tried using the render function of Email template module but it doesnt work. Below are some code that i have tried.
Method 1:
function render(template, dataNext) {
return template(dataNext);
}
const tpl = () => `${myDBObject[0].template}`;
console.log(render(tpl, { countryName: "India", departmentName: "science"}));
Above i have hardcoded India just for understanding purpose and that value will also come from database.
Im expecting some es6 ways to replace these containers with my values.