ES6 template literals based on template variable [duplicate]
问题 This question already has answers here : Convert a string to a template string (18 answers) Closed 3 years ago . I try to render a ES6 template literal variable : function render(template, data){ ... } const template = 'resources/${id}/'; console.log(render(template, {id: 1})); // -> resources/1/ Does exist a way to transform a string template with context into a formated string with ES6 template literals feature ? 回答1: You can not do this with simple template literals. However, you can