DOM Templating API Proposal: Explainer

3 points by yawaramin


yawaramin

TL;DR:

const {html} = DOMTemplate;

// Define a "template function" - a function that evaluates a template
// expression and returns a TemplateResult:
const page = (title, body) => html`
  <h1>${title}</h1>
  <p>${body}></p>
`;

// Render the page once:
document.body.render(page('Hello Templates', 'abc'));

// Re-render the page with different data:
document.body.render(page('Hello Updates', 'def'));