Render
render() { return html`<p>template</p>`; }
Properties, loops, conditionals
// Property
html`<p>${this.myProp}</p>`;
// Loop
html`${this.myArray.map(i => html`<li>${i}</li>`;)}`;
// Conditional
html`${this.myBool?html`<p>foo</p>`:html`<p>bar</p>`}`;
Data bindings
// Attribute
html`<p id="${...}">`;
// Boolean attribute
html`<input type="checkbox" ?checked="${...}">`;
// Property
html`<input .value="${...}">`;
// Event handler
html`<button @click="${this.doStuff}"></button>`;
Composition
// From multiple templates on same class
render() {
return html`
${this.headerTemplate}
<article>article</article>
`;
}
static get headerTemplate() {
return html`<header>header</header>`;
}
// By importing elements
import './my-header.js';
class MyPage extends LitElement{
render() {
return html`
<my-header></my-header>
<article>article</article>
`;
}
}
Slots
render() { return html`<slot name="thing"></slot>`; }
<my-element>
<p slot="thing">stuff</p>
</my-element>