Articles in this section

#startsWith helper

The #startsWith block helper checks whether a string begins with a specified prefix and renders one expression if it matches, or an optional {{else}} expression if it doesn't. Use it to validate prefixes in IDs, codes, or name fields.

Syntax

{{#startsWith prefix testString}} expr {{else}} expr {{/startsWith}}

prefix -- The prefix to check for. Required. Matching is case-sensitive: "Hello" does not match "hello".

testString -- The string to test. Required.

Examples

Check whether a greeting starts with a specific word

{{#startsWith "Hello" record.greeting}}Match!{{else}}No match{{/startsWith}}
{{#startsWith "Goodbye" record.greeting}}Wrong!{{else}}Still here{{/startsWith}}

Input:

{ "record": { "greeting": "Hello, world!" } }

Output:

Match!
Still here

record.greeting starts with "Hello" so the first expression renders its main block. It does not start with "Goodbye" so the second expression renders its {{else}} block.

Check whether a name starts with a specific string

{{#startsWith "Jane" record.firstName}}
  Welcome, Jane!
{{else}}
  User not Jane
{{/startsWith}}

Input:

{ "record": { "firstName": "Jane Doe" } }

Output: Welcome, Jane!

Usage notes

  • Matching is case-sensitive: "Hello" does not match "hello".
  • If either prefix or testString is missing, undefined, or the helper call is malformed, the helper returns an empty string rather than an error.
  • The {{else}} clause is optional. If omitted and the string doesn't match the prefix, the helper renders nothing.