String Functions Guide
Updated Jun 19, 2026
DataMagik DocumentsString Functions Guide
Format and present text in DataMagik document templates.
Important: The case-conversion helpers
upper, lower, title, and trim (and now) are registered for ZPL label templates only — they are not available in HTML/PDF document templates. In document templates, format text with printf and the helpers below.1. printf — the primary string formatter
Use printf for nearly all text formatting in document templates. It follows Go's formatting verbs.
{{printf "%s" .Name}} <!-- string -->
{{printf "%.2f" .Amount}} <!-- 1500.5 -> 1500.50 -->
{{printf "$%.2f" .Total}} <!-- 1500.50 -> $1500.50 -->
{{printf "%05d" .Number}} <!-- 42 -> 00042 -->
{{printf "%-20s|" .Label}} <!-- left-padded to 20 -->
{{printf "Hello, %s!" .Name}} <!-- combined text -->| Verb | Meaning | Example |
|---|---|---|
%s | String | {{printf "%s" .Name}} |
%d | Integer | {{printf "%d" .Qty}} |
%.2f | Float, 2 decimals | {{printf "%.2f" .Price}} |
%05d | Zero-padded integer | {{printf "%05d" .Id}} |
%-20s | Left-justified, width 20 | {{printf "%-20s" .Name}} |
2. toString — coerce a value to text
Convert any value (number, boolean, etc.) to its string form before output or comparison.
{{toString .InvoiceNumber}}3. Safe field access
These document helpers guard against missing fields when working with flexible data:
safeGet— return a field's value or an empty string if absent:{{safeGet . "customer_name"}}hasField— test whether a field exists:{{if hasField . "notes"}}...{{end}}isSet/notEmpty— test for present / non-empty values.
4. Case conversion (ZPL label templates only)
Within ZPL label templates you can normalize case and trim whitespace with upper, lower, title, and trim. These are not available in HTML/PDF document templates.
^FD{{upper .PartName}}^FS <!-- ZPL: WIDGET -->
^FD{{trim .Operator}}^FS <!-- ZPL: trimmed -->Quick reference
| Function | Available in | Purpose |
|---|---|---|
printf | Documents + ZPL | Formatted strings/numbers |
toString | Documents + ZPL | Coerce value to text |
safeGet, hasField, isSet, notEmpty | Documents | Safe field access |
upper, lower, title, trim | ZPL labels only | Case conversion / trim |