Reputation: 71
I have searched on the internet, but I can't find the right syntax in javascript or jquery "finally if it's possible" to do for example ->
test.js
array = {title: 'hihihi',
Name: 'hahaha',};
array.forEach((array) => { var template = load('test.html')});
$("#ok").html(template);
test.html
<div id="test">${array.title}</div>
index.html
<div id="ok"></div>
is it possible to do this or not?
UPDATE
here is the solution I found:
test.js
async function writeTemp(arg) {
var template = "";
template = await (await fetch('test.html')).text();
template = eval("`" + template + "`");
Object.keys(arg).forEach(prez => {
template;
});
$("#ok").html(template);
}
writeTemp(array);
test.html
<div id="test">${arg.title}</div>
index.html
<div id="ok"></div>
Thanks in advance.
Upvotes: 1
Views: 553
Reputation: 856
I know eval is not much liked but this seems to be the only solution to your question.
var array = {
title: 'hihihi',
Name: 'hahaha',
};
var template = load('test.html')
template = eval("`" + template + "`");
$("#ok").html(template);
Upvotes: 1