0

I am trying to implement string interpolation by letting user provide template from the form.

Consider these inputs:

  • Input with id mapping_template
  • Input with id key
  • Input with id value

When users type following in inputs:

  1. mapping_template has value ${key} = ${value}
  2. key has value a key
  3. value has value the value

This is my function, I invoke it like so interpolateMappingTemplate (mapping_template, 'a key', 'the value') :

var interpolateMappingTemplate = function(mappingTemplate, key, value) {
  return `${templateString}`;
}

I was expecting when I interpolate template to get this a key = the value but instead my function outputs ${key} = ${value}.

What am I doing wrong here?

Remember_me
  • 223
  • 4
  • 18
  • You cannot convert the content of a variable into a template string just by "wrapping" it in backticks -> [Convert a string to a template string](https://stackoverflow.com/questions/29182244/convert-a-string-to-a-template-string) – Andreas Aug 06 '19 at 10:41
  • can you make that an answer? – Remember_me Aug 06 '19 at 16:48

0 Answers0