sercrod

*unwrap

Summary

*unwrap removes the Sercrod host element itself from the DOM after rendering and leaves only its children. It is a host-level directive: it is evaluated on <serc-rod> instances, not on arbitrary elements. The attribute is treated as boolean; its value is ignored, and only its presence matters.

This directive is useful when you want to use Sercrod as a one-shot renderer or build tool but do not want the <serc-rod> tag to remain in the final HTML.

Basic example

Simple one-shot render of a card:

<serc-rod id="card" *unwrap data='{"title":"Hello","body":"World"}'>
  <article class="card">
    <h1 *print="title"></h1>
    <p *print="body"></p>
  </article>
</serc-rod>

After the initial render and finalization, the DOM becomes effectively:

<article class="card">
  <h1>Hello</h1>
  <p>World</p>
</article>

Behavior

Evaluation timing

*unwrap is evaluated in the host’s _finalize() phase:

Consequences:

Execution model

The internal execution model for *unwrap on a <serc-rod> host is:

  1. At the end of an update, the host calls _finalize().

  2. _finalize() calls _unwrap() on the host.

  3. _unwrap() performs:

    • Check: if the host does not have the *unwrap attribute, stop and do nothing.
    • Find the parent node of the host; if there is no parent, stop.
    • Create an empty DocumentFragment.
    • Move all existing child nodes from the host into the fragment, in order.
    • Replace the host element in its parent with that fragment.
  4. After this replacement:

    • The former children now live directly under the parent.
    • The <serc-rod> host element is no longer in the DOM.

No additional scopes or variables are created by *unwrap during this process; it only affects DOM structure after rendering.

Variable creation and scope layering

In other words, *unwrap is purely structural and post-render; it does not participate in expression evaluation.

Parent access

Use with conditionals and loops

*unwrap does not itself provide conditional behavior or looping; it runs unconditionally whenever the attribute is present and the host completes an update.

Typical combinations:

Best practices

Additional examples

Unwrapping a layout section:

<serc-rod id="hero" *unwrap data='{
  "title": "Sercrod",
  "tagline": "HTML-first data binding"
}'>
  <section class="hero">
    <h1 *print="title"></h1>
    <p *print="tagline"></p>
  </section>
</serc-rod>

The final HTML keeps only the <section> and its contents, without <serc-rod>.

Combining with partials inside:

<serc-rod id="page" *unwrap data='{"user":{"name":"Alice"}}'>
  <main>
    <header *include="'site-header'"></header>
    <section *include="'user-profile'"></section>
  </main>
</serc-rod>

Notes