bitty installation snippets examples documentation q&a

snippets

use a template from the page

  • HTML templates can be included directly on a page by embedding them in <script> tags with type="text/html" and data-template="NAME" attributes.
  • The <script> tag is used instead of <template> to prevent issues with some browsers attempting to load images from <template> tags before they are used.

html

<button data-s="snippet" data-r="snippet">
  switch to template
</button>

<script 
  type="text/html" 
  data-template="exampleTemplate">
  <div>example text from the template</div>
</script>

javascript

export const b = {};

export function snippet(_, __, el) {
  el.replaceWith(
    b.render("exampleTemplate"),
  );
}