これは非常に簡単です。テンプレートを使用すると、それはなくなります。したがって、コンテンツを繰り返すには、必要なコンテンツでテンプレートを更新し、そのクローンを作成して、作成したばかりのクローンを使用するだけです。
JSFiddle の例
if ('content' in document.createElement('template')) {
var target = document.querySelector('.content-container'),
aside = target.content.querySelectorAll("aside");
aside[0].textContent = "Shadow DOM Content";
aside[1].textContent = "More Shadow DOM Content";
aside[2].textContent = "Even More Content!";
// Clone the new row and insert it into the table
var section = document.getElementsByClassName("first-section")
var clone = document.importNode(target.content, true);
section[0].appendChild(clone);
// Create a new row
aside[0].textContent = "test 1";
aside[1].textContent = "test 2";
aside[2].textContent = "test 3";
// Clone the new row and insert it into the table
var clone2 = document.importNode(target.content, true);
section[0].appendChild(clone2);
} else {
// do something else
}
body {
background: lightgrey;
}
.first-section aside {
background: grey;
padding: 5px;
}
.first-section aside:nth-child(3n) {
margin-bottom: 15px;
}
<div>
<div class="first-section">
A repeated use of template:
<div>
</div>
<template class="content-container">
<aside></aside>
<aside></aside>
<aside></aside>
</template>
この方法を使用すると、テンプレートを何度でも再利用できます。