I have a unique use-case scenario where I am filling the innerHTML
like this. However, my issue lies in resolving the template literal within the context of a for loop. Any suggestions on how to accomplish this?
var blog_entries_dom = 'blog_entries';
var blog_entries = [
{
"title": "Hello World",
"id": 2,
"body": "<p>Hello World</p>"
},
{
"title": "World Hello",
"id": 3,
"body": "<p>World Hello</p>"
}
];
var blog_entry_template = `<div class="post-preview">
<a href="post.html">
<h2 class="post-title">
${item.title}
</h2>
<h3 class="post-subtitle">
${item.body}
</h3>
</a>
<p class="post-meta">Posted by <a href="#">Start Bootstrap</a> #Created At </p>
</div>
<hr>`;
var populate_children = function (element_id, objects_list, template) {
var element = document.getElementById(element_id);
var html = '';
for (var i = 0; i < list.length; i++) {
var item = list[i]
html += template;
}
element.innerHTML = html;
};
populate_children(blog_entries_dom, blog_entries, blog_entry_template);