Runtime verified

Syntax

v(variableName)  →  string
1 argument — exactly

Parameters

Name Type Required Description
variableName string | number Yes Variable reference, literal or nested function call to output

Example

%%[
  VAR @word
  SET @word = "zeta"
]%%
<p>%%=v(@word)=%%</p>

Renders <p>zeta</p>.

The argument does not have to be a variable — a function call can be passed straight in, which saves declaring one:

<p>Hello, %%=v(RequestParameter("p"))=%%</p>

Requested with ?p=hello, that renders <p>Hello, hello</p>. Beware the mirror image of it, though: a quoted name is output as itself rather than resolved — see below.

Return value

string — the referenced value rendered as a string.

The value domain is open, so there is no closed set of tokens to test against.

Behaviour

A variable is output as its value. A variable set to a word rendered that word; a variable holding a request-parameter value rendered that value.

A nested function call is evaluated. Wrapping a request-parameter read rendered the parameter’s value, identical to reading it into a variable first.

A number is accepted, both from a variable and as a bare literal: v(5) renders 5.

A quoted name is output as itself

v("p") renders the letter p — the literal, not whatever p might name. This is the one trap on the page: write v("id") where you meant v(RequestParameter("id")) and the page renders the word id at HTTP 200 rather than failing, so the mistake ships silently. Neither the official reference nor the community guide mentions that a literal is accepted at all.

Show test script
%%[
  VAR @b, @rp, @qp, @word, @num
  SET @b = RequestParameter("b")
  SET @word = "zeta"
  SET @num = 7

  /* known-good control: renders on every request, so a run of HTTP 422s
     can be told apart from a broken deploy */
  OutputLine(Concat("CTRL=[", Uppercase("ok"), "]"))
  OutputLine(Concat("GATE=[", @b, "]"))

  /* a parameter this request set itself, read by both functions and
     compared in-page */
  IF @b == "basic" THEN
    OutputLine(Concat("--- basic start ---"))
    SET @rp = RequestParameter("p")
    SET @qp = QueryParameter("p")
    OutputLine(Concat("RP=[", @rp, "] LEN=[", Length(@rp), "]"))
    OutputLine(Concat("QP=[", @qp, "] LEN=[", Length(@qp), "]"))
    OutputLine(Concat("EQ=[", IIf(@rp == @qp, "same", "diff"), "]"))
    OutputLine(Concat("--- basic done ---"))
  ENDIF

  /* percent-encoded and plus-encoded values arrive decoded; the length
     proves a real single character rather than the escape sequence */
  IF @b == "enc" THEN
    OutputLine(Concat("--- enc start ---"))
    OutputLine(Concat("SP=[", RequestParameter("sp"), "] LEN=[", Length(RequestParameter("sp")), "]"))
    OutputLine(Concat("AM=[", RequestParameter("am"), "] LEN=[", Length(RequestParameter("am")), "]"))
    OutputLine(Concat("PL=[", RequestParameter("pl"), "]"))
    OutputLine(Concat("PC=[", RequestParameter("pc"), "]"))
    OutputLine(Concat("SP_QP=[", QueryParameter("sp"), "]"))
    OutputLine(Concat("AM_QP=[", QueryParameter("am"), "]"))
    OutputLine(Concat("--- enc done ---"))
  ENDIF

  /* a parameter the request never carried: empty at HTTP 200 */
  IF @b == "absent" THEN
    OutputLine(Concat("--- absent start ---"))
    SET @rp = RequestParameter("nosuchparam")
    SET @qp = QueryParameter("nosuchparam")
    OutputLine(Concat("ABS_RP=[", @rp, "] LEN=[", Length(@rp), "]"))
    OutputLine(Concat("ABS_RP_CHK=[", IIf(Empty(@rp), "empty", "not-empty"), "]"))
    OutputLine(Concat("ABS_QP_CHK=[", IIf(Empty(@qp), "empty", "not-empty"), "]"))
    OutputLine(Concat("--- absent done ---"))
  ENDIF

  /* the name ignores case: fetch with a single mixed-case parameter */
  IF @b == "case" THEN
    OutputLine(Concat("--- case start ---"))
    OutputLine(Concat("LOW=[", RequestParameter("foo"), "] UPP=[", RequestParameter("FOO"), "] MIX=[", RequestParameter("Foo"), "]"))
    OutputLine(Concat("LOW_QP=[", QueryParameter("foo"), "] UPP_QP=[", QueryParameter("FOO"), "] MIX_QP=[", QueryParameter("Foo"), "]"))
    OutputLine(Concat("--- case done ---"))
  ENDIF

  /* the same name twice: joined by a comma, proven by the length */
  IF @b == "dup" THEN
    OutputLine(Concat("--- dup start ---"))
    OutputLine(Concat("DUP_RP=[", RequestParameter("x"), "] LEN=[", Length(RequestParameter("x")), "]"))
    OutputLine(Concat("DUP_QP=[", QueryParameter("x"), "]"))
    OutputLine(Concat("--- dup done ---"))
  ENDIF

  /* a name the platform supplies although the request never set it —
     and, with ?b=plat&PAGEURL=zzz, a caller value overriding it */
  IF @b == "plat" THEN
    OutputLine(Concat("--- plat start ---"))
    OutputLine(Concat("PAGEURL_RP=[", RequestParameter("PAGEURL"), "]"))
    OutputLine(Concat("PAGEURL_QP=[", QueryParameter("PAGEURL"), "]"))
    OutputLine(Concat("PAGENAME=[", RequestParameter("PAGENAME"), "]"))
    OutputLine(Concat("MID=[", RequestParameter("MID"), "]"))
    OutputLine(Concat("--- plat done ---"))
  ENDIF

  /* v() outputs a variable, a literal, a number and a nested call */
  IF @b == "vread" THEN
    OutputLine(Concat("--- vread start ---"))
    SET @rp = RequestParameter("p")
    OutputLine(Concat("V_VAR=[", v(@rp), "]"))
    OutputLine(Concat("V_LIT=[", v("p"), "]"))
    OutputLine(Concat("V_WORD=[", v(@word), "]"))
    OutputLine(Concat("V_NUM=[", v(@num), "]"))
    OutputLine(Concat("--- vread done ---"))
  ENDIF

  IF @b == "vnest" THEN
    OutputLine(Concat("--- vnest start ---"))
    OutputLine(Concat("V_NEST=[", v(RequestParameter("p")), "]"))
    OutputLine(Concat("--- vnest done ---"))
  ENDIF

  IF @b == "vnumlit" THEN
    OutputLine(Concat("--- vnumlit start ---"))
    OutputLine(Concat("V_NUMLIT=[", v(5), "]"))
    OutputLine(Concat("--- vnumlit done ---"))
  ENDIF

  /* an empty name and a numeric name: accepted, always empty */
  IF @b == "rpempty" THEN
    OutputLine(Concat("--- rpempty start ---"))
    OutputLine(Concat("RPEMPTY=[", RequestParameter(""), "] QPEMPTY=[", QueryParameter(""), "]"))
    OutputLine(Concat("--- rpempty done ---"))
  ENDIF

  IF @b == "rpnum" THEN
    OutputLine(Concat("--- rpnum start ---"))
    OutputLine(Concat("RPNUM=[", RequestParameter(1), "] QPNUM=[", QueryParameter(1), "]"))
    OutputLine(Concat("--- rpnum done ---"))
  ENDIF

  /* argument counts the signatures do not allow: each aborts its own
     branch with HTTP 422 while every branch above still renders */
  IF @b == "rp0" THEN
    OutputLine(Concat("RP0=[", RequestParameter(), "]"))
  ENDIF
  IF @b == "rp2" THEN
    OutputLine(Concat("RP2=[", RequestParameter("p", 1), "]"))
  ENDIF
  IF @b == "qp0" THEN
    OutputLine(Concat("QP0=[", QueryParameter(), "]"))
  ENDIF
  IF @b == "qp2num" THEN
    OutputLine(Concat("QP2NUM=[", QueryParameter("p", 1), "]"))
  ENDIF
  IF @b == "qp2zero" THEN
    OutputLine(Concat("QP2ZERO=[", QueryParameter("p", 0), "]"))
  ENDIF
  IF @b == "qp2bool" THEN
    OutputLine(Concat("QP2BOOL=[", QueryParameter("p", true), "]"))
  ENDIF
  IF @b == "v0" THEN
    OutputLine(Concat("V0=[", v(), "]"))
  ENDIF
  IF @b == "v2" THEN
    OutputLine(Concat("V2=[", v(@word, @word), "]"))
  ENDIF
]%%

The bundled harness is shared with the two request-reading functions above; its ?b=vread, ?b=vnest, ?b=vnumlit, ?b=v0 and ?b=v2 branches are the ones belonging to this function. Everything claimed here was proven on Marketing Cloud Engagement; the Marketing Cloud Next availability below is read from the official reference, not from a probe.

Availability

Platform Available
Marketing Cloud Engagement Yes
Marketing Cloud Next Yes, from API 67.0

See also