2

In ES6/ES2015 I am importing a string from a JSON file:

import config from './file.json';

config.string; // => "${foo} does things"

Now I want to use that string as a template string in another function. All docs I can find will do it like

(foo) => `${foo} does things`

but I could not find anything on how to turn a "plain" string into a template string.

Is this even possible?

m90
  • 11,434
  • 13
  • 62
  • 112
  • 1
    did you get a chance to stumble upon this line Template strings are enclosed by the back-tick (` `) at the link you mentioned , so how about x = "`"+x+"`" now x should behave like a template string – Satya Jul 10 '15 at 08:36
  • I just tried this and did not get it to work, it just inserted backticks. But maybe I don't get what you're trying to say yet. – m90 Jul 10 '15 at 08:45
  • You seem to be looking for a template engine, not string interpolation. – Bergi Jul 10 '15 at 08:48
  • They are called "template literals" btw. – Felix Kling Jul 10 '15 at 10:38
  • MDN calls them strings though, so I won't be going to ES6 hell hopefully. – m90 Jul 10 '15 at 11:11

0 Answers0