The Liquid template string to process.
The default message prefix to use for missing variables.
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
Ensures that each Liquid variable in the template string includes a
defaultfilter. If a variable already has adefaultfilter, it is left unchanged. Otherwise, it appends adefaultfilter with a placeholder message indicating the missing variable name.