I want to use a statically defined template for URL building.
I'm trying to use ES6 string interpolation feature for this
var template = "http://example.com/?name=${name}&age=${age}";
var name = "John";
var age = "30";
var url = `${template}`;
Expected result: http://example.com/?name=John&age=23
Actual result: http://example.com/?name=${name}&age=${age}
In case this can't be done with string interpolation is there any better method than String.prototype.replace
like
var url = template.replace(/\${name}/,"John").replace(/\${age}/, 23);