I have a map of templates structured like this:
const templateMap = {
greeting: `Hello, ${name}`,
farewell: `Goodbye, ${name}`
}
However, I am facing an issue where I need to apply the 'name' variable after defining the map. I came across a solution involving treating the templates as strings and utilizing
eval("`"+template+"`")
, but I find this approach unappealing.
Is there a way to specify when the variables in the templates should be applied? Is there a method to convert a string into a pre-defined template?