Skip to content
Forms, switch product

String Interpolation

String interpolation lets you embed live values directly in widget text props using {{expression}} slots — no callbacks, no custom widgets. Slots re-evaluate reactively as the user fills in the form.

import { gui } from '@golemui/gui-shared';
gui.displays.alert({
uid: 'greeting',
text: "Hello {{$form.firstName}}, you have {{$formIsInvalid ? 'errors' : 'no errors'}}.",
});
{
"kind": "display",
"type": "alert",
"props": {
"text": "Hello {{$form.firstName}}, you have {{$formIsInvalid ? 'errors' : 'no errors'}}."
}
}

Any string-valued widget property supports {{...}} slots: props.text, label, hint, placeholder, props.md, and any other string prop accepted by a widget. Display widgets are the most common use case, but the feature is not limited to them.

ScopeWhat it holds
$formAll current field values — the live form data object
$metaHost-supplied metadata passed via the meta prop
$errorsCurrent validation error messages of the visible inputs, keyed by data path
$formIsInvalidBoolean: true when any visible input currently fails validation
$fnPure functions supplied by the host — see Host Functions

Access nested values with standard dot notation: {{$form.address.city}}. Use optional chaining when the field may not yet exist: {{$form.address?.city}}.

Inside a repeater’s props.template, two more scope variables are available: $item (the current row) and $index (its zero-based position). See Repeater - $item and $index.

Slots support a safe subset of JavaScript — everything must stay a pure read, with no side effects and no assignments. You can use:

  • Path access — {{$form.user.name}}
  • Arithmetic — {{$form.count + 1}}, {{$form.price * 1.2}}
  • String concatenation — {{$form.firstName + ' ' + $form.lastName}}
  • Ternary — {{$meta.isVip ? 'VIP' : 'Guest'}}
  • Optional chaining — {{$form.address?.city}}
  • Nullish coalescing — {{$form.nickname ?? $form.firstName}}
  • Comparisons — {{$form.score >= 90 ? 'A' : 'B'}}
  • Host function calls — {{$fn.grandTotal($form.items)}}

The only calls allowed are host functions under $fn and a short list of methods that read a value, such as {{$form.tags.includes('vip')}} or {{$form.price.toFixed(2)}}: see What expressions can do for the list and the rules. When an expression starts to look like real logic, move it into a host function. See Host Functions.

import { gui } from '@golemui/gui-shared';
const formDef = [
gui.displays.alert({ uid: 'result', text: 'Next item: {{$form.count + 1}}' }),
gui.displays.alert({ uid: 'name', text: "Full name: {{$form.firstName + ' ' + $form.lastName}}" }),
gui.displays.alert({ uid: 'role', text: "Role: {{$meta.isVip ? 'VIP' : 'Guest'}}" }),
];
{
"form": [
{
"uid": "result",
"kind": "display",
"type": "alert",
"props": { "text": "Next item: {{$form.count + 1}}" }
},
{
"uid": "name",
"kind": "display",
"type": "alert",
"props": {
"text": "Full name: {{$form.firstName + ' ' + $form.lastName}}"
}
},
{
"uid": "role",
"kind": "display",
"type": "alert",
"props": { "text": "Role: {{$meta.isVip ? 'VIP' : 'Guest'}}" }
}
]
}

If an expression evaluates to null or undefined, the slot renders as an empty string — not the literal "null". For example, Hello {{$form.name}} renders as Hello while name is still empty.

Use $errors and $formIsInvalid to reflect live validation feedback inline:

import { gui } from '@golemui/gui-shared';
gui.displays.alert({
uid: 'validation_status',
text: 'Form valid: {{!$formIsInvalid}} | Username error: {{$errors.userName}}',
});
{
"kind": "display",
"type": "alert",
"props": {
"text": "Form valid: {{!$formIsInvalid}} | Username error: {{$errors.userName}}"
}
}

$errors has the same shape as $form. $errors.userName is the array of current error messages of the input at the path userName, and it is undefined when that input has no error or is hidden. A nested path nests the same way: the input at address.city has its messages at $errors.address?.city, and $errors.address?.city?.[0] reads the first one. $formIsInvalid is a plain boolean - use it as-is: {{$formIsInvalid}} or inside a ternary: {{$formIsInvalid ? 'Fix errors first' : 'Ready'}}.

If a slot doesn’t parse, such as {{$form..broken}}, or fails while it runs, GolemUI reports the problem through the formHealth callback with { status: 'errored', code: 40 }. A slot the expression check rejects, such as {{$form.x = 1}}, which writes into the data, reports code: 50 and leaves the data unchanged. This surfaces definition mistakes at runtime rather than silently producing wrong output.

The form keeps its last good render while it is errored, and computes everything again on the next change: a slot that fails only for some data recovers as soon as the data allows. A slot that can never run, such as a syntax error, stays errored until the definition is corrected.