Template interpolation

I want to generate a TTS dynamically based on the input language

<script>
audio = document.getElementById("audio");
lang = "en_US";

audio.innerHTML = `{{ tts ${lang} word }}`;
</script>

the previous script generates a tts element, but couldn’t interpret the interpolated variable, i.e. didn’t replace ${lang} with its value.

there are some other issues here:
1- using let or var to define audio causes the script not to run at all

let audio = ....
var audio = ....
audio = ... // only this works

2- using double quotations also causes the script not working

audio.innerHTML = "{{tts word}}"; //not working
audio.innerHTML = `{{tts word}}` // working
1 Like

Templates are rendered prior to being inserted on the page, so you can’t use JS to generate them.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.