I have been attempting to substitute values in a string template using the following method:
for (var i in replacements) {
var regexp = new RegExp('\$\{' + i + '\}', 'g');
template = template.replace(regexp, replacements[i]);
}
Below is the template in which I am trying to substitute values:
<?php
class ${className} {
}
When I use console.log(i, replacements[i])
, it displays className
Test
. However, it does not actually replace it in the final template. The modification does not occur at all. Am I missing something?
The desired output should look like this:
<?php
class Test {
}