JS HTML5 — how to insert variables?

Good day.
Tell me, please how this remarkable technology to realize the insert of variables.

Is html5 )) tag - it's all great.

<template id="tpl">
the <div>**counter**</div>
 <img class="infinitimg" src="img/**counter**.png">
 </template>


I take it that is inserted to html and everything works. But how to make what you could in your JS code to insert the variables in these templates? How to do that would **counter** in the cycle has changed. This is what you need for all nodes to go looking for **counter**, that would replace to do this? Is there any method simpler. It's kind of like the templates the same
March 19th 20 at 08:33
1 answer
March 19th 20 at 08:35
Solution
Can, for example, use https://lodash.com/docs/4.17.11#template
const compiled = _.template(`<div><%= counter %></div>
 <img class="infinitimg" src="img/<%= counter %>.png">`);
compiled({ 'counter': 1 });
// => '<div>1</div><img class="infinitimg" src="img/1.png">'

Find more questions by tags HTMLJavaScript