Handlebars encodeURI
Handlebars encodeURI: URL-encodes a whole string so it can be placed in a link.
Next
Runtime verified
Differs from official docs
Test scripts included
URL-encodes a whole string so it can be placed in a link. For only the part behind the address, such as a query string, use encodeURIComponent.
Syntax
{{encodeURI text [onlySpaces]}}
Returns string.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
text |
string | Yes | The text to encode. |
onlySpaces |
boolean | No | true replaces just spaces with %20; false (default) encodes every URL-unsafe character. |
Example
Tested in a Marketing Cloud Next email on 2026-11-22:
{{encodeURI "a b/c" true}}breaks the email preview (HTTP 500). The documented result isa%20b/c.{{encodeURI "a b"}}rendersa b.
Show Next test script
Show calls that fail in Next (one email each)
Differs from official docs
- The reference says that when
onlySpacesis left out (it defaults tofalse), anything that does not belong in a URL gets percent-encoded. In Marketing Cloud Next (tested 2026-11-22):{{encodeURI "a b"}}rendereda b: the space stayed as it is. A link built this way still contains a raw space. Details - The reference says that with
onlySpacesset totrue, only spaces are converted (to%20). In Marketing Cloud Next (tested 2026-11-22):{{encodeURI "a b/c" true}}let the email save and publish, but the preview then failed with HTTP 500 and no message instead of renderinga%20b/c. Details
Marketing Cloud Next
Differs from the documentation
Without the second argument, {{encodeURI "a b"}} renders a b with the space left as is, although encoding everything is the documented default. With true, {{encodeURI "a b/c" true}} breaks the email preview (HTTP 500) instead of giving a%20b/c. Tested 2026-11-22 by rendering in a Marketing Cloud Next email.