Websites v4 docs v5.2.5
    Preparing search index...

    Function injectDefaultFilter

    • Ensures that each Liquid variable in the template string includes a default filter. If a variable already has a default filter, it is left unchanged. Otherwise, it appends a default filter with a placeholder message indicating the missing variable name.

      Parameters

      • template: string

        The Liquid template string to process.

      • defaultText: string = 'missing variable'

        The default message prefix to use for missing variables.

      Returns string

      The updated template string with default filters injected where needed.

      const template = '{{ brand_name }}';
      const output = injectDefaultFilter(template);
      // output: '{{ brand_name | default: "[missing variable: brand_name]" }}'

      Regex match details:

      • match: The full Liquid tag including any filters, e.g. {{ brand_name | upcase }}
      • expression: The inner expression inside the tag, e.g. brand_name | upcase