TemplateText

TemplateText

HkTemplateText is the read-only half of the fill-template surfaces: a {{ token }} template renders as its literal text runs plus one inline chip per token, so a stored template reads in a row, a card or a detail view exactly as it reads in the editor that produced it. Rendering is pure display — the grammar's parse and serialize are byte-exact inverses, so nothing shown here ever rewrites what storage holds.

  • The editable counterpart is HkTemplateField; both share one grammar and one chip style.
  • A plain string with no placeholders needs no component at all.

Import

tsx
1
import { HkTemplateText, type HkTemplateTokenDef } from "@celestia-island/hikari";
rust
1
2
use hikari_components::*;          // TemplateText, TemplateTokenDef
use hikari_components::prelude::*; // rsx!, VNode

Literal text and chips

Only {{ word }} with a bare identifier inside — [A-Za-z0-9_] — is a token; everything else stays literal text, so a richer engine grammar is never silently rewritten by merely rendering through this component. A chip always spells the canonical {{ name }} form, whatever spacing the stored value used.

Hi {{ email }}, your key is {{ md5_email }}.

The vocabulary's description becomes the chip's title, so a rendered row still explains itself on hover. label and group are menu-side fields; the read-only path never renders them.

Unknown tokens and multiline

A token outside the vocabulary still chips up, marked data-unknown — a renderer must not silently hide a value it does not understand. multiline swaps the inline run for a wrapping block, which is what long URLs in a narrow column need.

{{ base }}/{{ lang }}/{{ path }}{{ base }}/very/long/path/{{ lang }}/index

API

Vue

Props

NameTypeDefaultRequired
contentString—✓
tokensArray as PropType<readonly HkTemplateTokenDef[]>() => []—
multilineBooleanfalse—

Rust

Props — TemplateText

PropTypeDefaultDescription
contentString""The raw template string, verbatim from storage (Vue: content, required there; "" here parses to an empty shell).
tokensVec<TemplateTokenDef>[]Vocabulary for descriptions / unknown marking.
multilineboolfalseWrap as a block (long URLs in narrow columns) instead of one inline run — the shell's data-multiline.

Accessibility

  • The component renders inline text plus non-interactive chips, so it adds no focus stop and no role: it is read as part of the surrounding sentence, which is what a preview needs.
  • The chip text is the canonical {{ name }} spelling, and its title carries the vocabulary description — hover and assistive technology get the same explanation.
  • An unknown token stays visible and marked rather than hidden, so a template with a stale placeholder is readable as broken instead of silently reading as complete.

Related components

  • HkTemplateField — the editable half: the same chips, with a vocabulary panel and a chip editor.
  • HkTagInput — a tag field over an ordered key array.
  • HkMoneyInput — a currency amount over canonical decimal text.