Runtime verified Test scripts included

Renders its block once for every item in an array, list or object.

Syntax

{{#each collection}}
  …
{{/each}}

Returns string.

Parameters

Name Type Required Description
collection array Yes The array, list or object to loop over.

Example

Tested in Marketing Cloud Next emails on 2026-11-22 and 2026-11-25:

  • {{#each (hash a="1" b="2")}}{{@key}}={{this}};{{/each}} renders a=1;b=2;, as documented.
  • With a list of two rows built in AMPscript (%%[ SET @rows = BuildRowsetFromJSON('[{"name":"Bob","age":27},{"name":"Ann","age":21}]', '$[*]', 1) ]%%), {{#each rows}}{{@index}}={{name}};{{/each}} renders 0=Bob;1=Ann;.
  • {{#each (jsonpath '[1,2,3]' "$")}}[{{this}}]{{/each}} renders [1][2][3].
Show Next test script
<!-- Marketing Cloud Next test script for the each 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=1;b=2;] got=[{{#each (hash a="1" b="2")}}{{@key}}={{this}};{{/each}}]</p>
<p>c2 expect=[0=Bob;1=Ann;] got=[%%[ SET @rows = BuildRowsetFromJSON('[{"name":"Bob","age":27},{"name":"Ann","age":21}]', '$[*]', 1) ]%%{{#each rows}}{{@index}}={{name}};{{/each}}]</p>
<p>c3 expect=[[1][2][3]] got=[{{#each (jsonpath '[1,2,3]' "$")}}[{{this}}]{{/each}}]</p>

Marketing Cloud Next

Works as documented

Looping over an object or a list rendered as documented. Rows built in AMPscript and arrays from jsonpath both work as lists. Tested 2026-11-25 by rendering in a Marketing Cloud Next email.

See also