Handlebars Helper Function: encodeURI

Converts a string to a format that is safe to use in a URL.

This function encodes an entire string. To encode only a query string that follows a URL, use encodeURIComponent.

This helper is available in the Winter ’27 release of Marketing Cloud Next.

ParameterTypeDescription
stringToEncodeStringRequired. The string to encode.
onlySpacesBooleanIf true, encodes spaces as %20 and ignores other characters. If false, encodes all characters that aren’t safe to use in URLs. The default value is false.

The function returns the URL-encoded string.

This example encodes a string of text so that it’s safe to include in a URL, converting all spaces and special characters.

The function returns this URL-encoded string: