sercrod

*textContent

Summary

*textContent sets the DOM textContent property of an element from an expression. It is a text-oriented directive, similar in spirit to *print, and is paired with the alias n-textContent.

Use *textContent when you want to explicitly bind an expression to an element’s textContent, ignoring any static child markup.

Basic example

Simple binding to a message:

<serc-rod id="app" data='{"message":"Hello Sercrod"}'>
  <p *textContent="message"></p>
</serc-rod>

Behavior:

Behavior

Short manual entry (built into Sercrod):

Expression evaluation

When Sercrod encounters an element with *textContent or n-textContent:

Error handling:

Cleanup:

Evaluation timing

*textContent is not a structural directive; it runs after the structural layer for an element has succeeded.

Rough evaluation order for a given element:

  1. Structural checks on the template node (host):

    • *if / n-if, *elseif / *else, *switch / n-switch, *each / n-each, *for / n-for, and similar control directives run at higher stages.
    • If a structural directive decides to drop or replace the element, *textContent does not run.
  2. Sercrod host checks and other element-level decisions.

  3. Rendering of a concrete DOM element (el) for this template node.

  4. Text directives:

    • If the element has *print, n-print, *textContent, or n-textContent, the combined branch for “print/textContent” is executed.
    • That branch sets el.textContent and appends el to the parent.
    • After this branch returns, Sercrod does not recurse into children and does not process other content directives for this element.
  5. Fallback text handling:

    • If there is no text directive, but the element has exactly one static text child, Sercrod may:
      • Copy the text verbatim, or
      • Expand %expr% placeholders via _expand_text, then assign the result to textContent.
  6. Other content directives:

    • Only when no text directive and no simple static-text optimization applies, Sercrod proceeds to check *compose / n-compose, *innerHTML / n-innerHTML, and so on.

Important consequence:

Execution model

The execution model for *textContent on one element can be summarized as:

  1. Sercrod creates a new DOM element el corresponding to the template node.

  2. It detects whether the element has any text directive:

    • *print, n-print, *textContent, n-textContent.
  3. If so:

    • It chooses the source attribute (with *print > n-print > *textContent > n-textContent priority).
    • It evaluates the expression and passes the result through the text filter.
    • It sets el.textContent to the filtered string.
    • It optionally removes the directive attributes from el depending on the cleanup configuration.
    • It appends el to the parent.
    • It returns early; no children are rendered and no other content directives are considered.
  4. If not:

    • The renderer falls back to static text or child-node rendering paths.

Combined with reactivity:

Variable creation and scope layering

*textContent does not create any new variables in the scope.

Inside the expression:

Scope behavior:

Parent access

*textContent has no special concept of “parent data” beyond what Sercrod already supplies:

Typical usage:

<serc-rod id="todo" data='{"items":[{"title":"Buy milk"}]}'>
  <ul *each="item of items">
    <li *textContent="item.title"></li>
  </ul>
</serc-rod>

Here, item is introduced by *each, and *textContent simply reads it.

Use with conditionals and loops

*textContent works well inside structural directives:

In all cases:

Interaction with other content directives

*textContent participates in the same “content choice” layer as *print, and it precedes other content directives:

Recommendation:

Best practices

Additional examples

Using *textContent with derived values:

<serc-rod id="price" data='{"price": 1200, "currency":"JPY"}'>
  <span *textContent="price + ' ' + currency"></span>
</serc-rod>

Inside a list with conditional prefix:

<serc-rod id="messages" data='{
  "messages": [
    { "important": true,  "text": "System update required" },
    { "important": false, "text": "Daily backup completed" }
  ]
}'>
  <ul *each="msg of messages">
    <li *textContent="(msg.important ? '[!] ' : '') + msg.text"></li>
  </ul>
</serc-rod>

Notes