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 is a%20b/c.
  • {{encodeURI "a b"}} renders a b.
Show Next test script
<!-- Marketing Cloud Next test script for the encodeURI helper. Paste it into the HTML component of a
     Next email and open the preview. Each line prints the result Next gave when the call
     was rendered on its own (expect) next to the result of this run (got).
     Assembled from single-call test emails (dates on the page); it has not been
     run as one email. Calls that make Next fail are listed separately. -->
<p>c1 expect=[a b] got=[{{encodeURI "a b"}}]</p>

Show calls that fail in Next (one email each)
<!-- Run each call below in its own Next email: one of them in a combined email
     would stop the whole preview or block the save. -->

<!-- email 1: expect that the email saves, but the preview fails (HTTP 500) -->
{{encodeURI "a b/c" true}}

Differs from official docs

  • The reference says that when onlySpaces is left out (it defaults to false), anything that does not belong in a URL gets percent-encoded. In Marketing Cloud Next (tested 2026-11-22): {{encodeURI "a b"}} rendered a b: the space stayed as it is. A link built this way still contains a raw space. Details
  • The reference says that with onlySpaces set to true, 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 rendering a%20b/c. Details

Marketing Cloud Next

See also