Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render across <template> element boundaries #72

Merged
merged 1 commit into from
Nov 11, 2024

Commits on Nov 8, 2024

  1. Render across <template> element boundaries

    Take, for example, a `<template>` that nests other `<template>`
    elements:
    
    ```html
    <template>
      <template>
        <div>{{x}}</div>
      </template>
    </template>
    
    <script type="module">
      import { TemplateInstance } from "@github/template-parts"
    
      const template = document.querySelector("template")
      const instance = new TemplateInstance(template, { x: "Hello world" })
    
      document.body.append(instance)
    </script>
    ```
    
    Prior to this change, the inner `<template>` element (and its child
    `<div>`) are unchanged and still render `{{x}}` as a text node.
    
    This change aims to bring support for templating across `<template>`
    boundaries. To achieve this behavior, add explicit
    [HTMLTemplateElement][] handling to the tree walking. When handling a
    `<template>` element, walk its content `DocumentFragment`, treating
    variables in the same as way as the outer `<template>` element.
    
    [HTMLTemplateElement]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLTemplateElement
    seanpdoyle committed Nov 8, 2024
    Configuration menu
    Copy the full SHA
    a27cd0b View commit details
    Browse the repository at this point in the history