Given the following html template:
<div class="Page">
Hello <slot name="personName"></slot>. Your name is <slot name="personName"></slot>.
</div>
How is it possible (if at all) to fill both slots with one value using custom elements?
The below demo code will produce:
Hello Bob, Your name is .
Is this intended? Is this the wrong way of displaying a single value in multiple locations of a template?
let tmpl = document.createElement("template");
tmpl.innerHTML = `
<div>
Hello <slot name="personName"></slot>. Your name is <slot name="personName"></slot>.
</div>
`;
class MyElement extends HTMLElement {
constructor() {
super();
let shadowRoot = this.attachShadow({ mode: "open" });
shadowRoot.appendChild(tmpl.content.cloneNode(true));
}
}
customElements.define("x-myelement", MyElement);
<x-myelement>
<span slot="personName">Bob</span>
</x-myelement>
"message": "ReferenceError: customElements is not defined"
in FF. – connexodocument.registerElement
from web components spec v0 probably works. – connexodocument.registerElement
is dead. Firefox will soon support the V1 spec. @Monokh's question is clearly about the V1 spec since it uses<slot>
@Monokh I do not believe that there is plans to have more then one slot able to take the same source elements. At least not as part of V1 – Intervalia