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
import { HkTemplateText, type HkTemplateTokenDef } from "@celestia-island/hikari";
use hikari_components::*; use hikari_components::prelude::*;
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 }}.
Hi {{ email }}, your key is {{ md5_email }}.
import { HkTemplateText, type HkTemplateTokenDef } from "@celestia-island/hikari";
const tokens: HkTemplateTokenDef[] = [
{ name: "email", label: "Email", description: "The address the message goes to" },
{ name: "md5_email", label: "Email hash", description: "Lower-case MD5 of the address" },
];
export default () => (
<HkTemplateText content="Hi {{email}}, your key is {{ md5_email }}." tokens={tokens} />
);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
let tokens = vec![
TemplateTokenDef {
name: "email".to_string(),
label: Some("Email".to_string()),
description: Some("The address the message goes to".to_string()),
group: None,
},
TemplateTokenDef {
name: "md5_email".to_string(),
label: Some("Email hash".to_string()),
description: Some("Lower-case MD5 of the address".to_string()),
group: None,
},
];
rsx! {
TemplateText { content: "Hi {{email}}, your key is {{ md5_email }}.".to_string(), tokens: tokens }
}
import { HkTemplateText, type HkTemplateTokenDef } from "@celestia-island/hikari";
const tokens: HkTemplateTokenDef[] = [
{ name: "email", label: "Email", description: "The address the message goes to" },
{ name: "md5_email", label: "Email hash", description: "Lower-case MD5 of the address" },
];
export default () => (
<HkTemplateText content="Hi {{email}}, your key is {{ md5_email }}." tokens={tokens} />
);let tokens = vec![
TemplateTokenDef {
name: "email".to_string(),
label: Some("Email".to_string()),
description: Some("The address the message goes to".to_string()),
group: None,
},
TemplateTokenDef {
name: "md5_email".to_string(),
label: Some("Email hash".to_string()),
description: Some("Lower-case MD5 of the address".to_string()),
group: None,
},
];
rsx! {
TemplateText { content: "Hi {{email}}, your key is {{ md5_email }}.".to_string(), tokens: tokens }
}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
{{ base }}/{{ lang }}/{{ path }}{{ base }}/very/long/path/{{ lang }}/index
import { HkTemplateText, type HkTemplateTokenDef } from "@celestia-island/hikari";
const tokens: HkTemplateTokenDef[] = [
{ name: "base", label: "Base URL", description: "The site's public origin" },
{ name: "lang", label: "Locale", description: "Two-letter language tag" },
];
export default () => (
<div style={{ display: "grid", gap: "12px", maxWidth: "22rem" }}>
<HkTemplateText content="{{ base }}/{{ lang }}/{{ path }}" tokens={tokens} />
<HkTemplateText content="{{ base }}/very/long/path/{{ lang }}/index" tokens={tokens} multiline />
</div>
);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
rsx! {
div { style: "display:grid;gap:12px;max-width:22rem",
TemplateText {
content: "{{ base }}/{{ lang }}/{{ path }}".to_string(),
tokens: vec![
TemplateTokenDef { name: "base".to_string(), label: Some("Base URL".to_string()), description: Some("The site's public origin".to_string()), group: None },
TemplateTokenDef { name: "lang".to_string(), label: Some("Locale".to_string()), description: Some("Two-letter language tag".to_string()), group: None },
],
multiline: false,
}
TemplateText {
content: "{{ base }}/very/long/path/{{ lang }}/index".to_string(),
tokens: vec![
TemplateTokenDef { name: "base".to_string(), label: Some("Base URL".to_string()), description: Some("The site's public origin".to_string()), group: None },
TemplateTokenDef { name: "lang".to_string(), label: Some("Locale".to_string()), description: Some("Two-letter language tag".to_string()), group: None },
],
multiline: true,
}
}
}
import { HkTemplateText, type HkTemplateTokenDef } from "@celestia-island/hikari";
const tokens: HkTemplateTokenDef[] = [
{ name: "base", label: "Base URL", description: "The site's public origin" },
{ name: "lang", label: "Locale", description: "Two-letter language tag" },
];
export default () => (
<div style={{ display: "grid", gap: "12px", maxWidth: "22rem" }}>
<HkTemplateText content="{{ base }}/{{ lang }}/{{ path }}" tokens={tokens} />
<HkTemplateText content="{{ base }}/very/long/path/{{ lang }}/index" tokens={tokens} multiline />
</div>
);rsx! {
div { style: "display:grid;gap:12px;max-width:22rem",
TemplateText {
content: "{{ base }}/{{ lang }}/{{ path }}".to_string(),
tokens: vec![
TemplateTokenDef { name: "base".to_string(), label: Some("Base URL".to_string()), description: Some("The site's public origin".to_string()), group: None },
TemplateTokenDef { name: "lang".to_string(), label: Some("Locale".to_string()), description: Some("Two-letter language tag".to_string()), group: None },
],
multiline: false,
}
TemplateText {
content: "{{ base }}/very/long/path/{{ lang }}/index".to_string(),
tokens: vec![
TemplateTokenDef { name: "base".to_string(), label: Some("Base URL".to_string()), description: Some("The site's public origin".to_string()), group: None },
TemplateTokenDef { name: "lang".to_string(), label: Some("Locale".to_string()), description: Some("Two-letter language tag".to_string()), group: None },
],
multiline: true,
}
}
}
API
Vue
Props
Rust
Props — TemplateText
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.