I am trying to replace values in a string template, and I am trying to do so like this:
for (var i in replacements) {
var regexp = new RegExp('\$\{' + i + '\}', 'g');
template = template.replace(regexp, replacements[i]);
}
Here is the template that I am trying to replace values in:
<?php
class ${className} {
}
When I do a console.log(i, replacements[i])
, I get className
Test
, but it doesn't replace it in the final template. It doesn't modify it at all. Am I doing this wrong?
The output I am looking for is this:
<?php
class Test {
}