Articles in this section

#startsWith helper

Renders the block if the test string begins with the specified prefix. If it doesn't match, renders the {{else}} block.

Usage

{{#startsWith prefix testString}}Block if match{{else}}Fallback{{/startsWith}}
  • prefix (required): the prefix to check for

  • testString (required): string to test against

Note

This helper produces an empty string when either the prefix or testString parameter is missing, undefined, or when the helper call is malformed.

Examples

  1. Check if a greeting starts with "Hello"

    {{#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
    
  2. Check if a customer name starts with "Jane"

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

    Input:

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

    Output:

    Welcome, Jane!
    

Tip

  • Matching is case-sensitive ("Hello""hello").

  • Use when validating prefixes in IDs, codes, or user inputs.