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.

Availability 

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

Syntax 

1{{encodeURI stringToEncode onlySpaces=true|false}}

Parameters 

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.

Return Value 

The function returns the URL-encoded string.

Usage Example 

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

1{{encodeURI "Sample Text: example" onlySpaces=false}}

The function returns this URL-encoded string:

1Sample+Text%3a+example

See Also