Building Lists and Tables in Custom Print Templates (tablerow, listrow, foreach)

  • Updated

Use foreach, listrow, and tablerow to display repeating data in your custom print template. These tags loop through multiple responses captured in a group question or an image question that allows multiple uploads.

Before you start

  • Read Set up a custom print for a form first. This article assumes you are familiar with placeholder codes and how to build a custom print template.
  • Find the variable codes for your group question and the questions inside it from the Custom Printing panel in the form editor.

Which tag should I use?

All three tags loop through repeating data. The difference is how the output is laid out in the PDF.

Tag Output layout Best used for
foreach Items placed horizontally, wrapping to next line when full Multiple images side by side; inline repeating values
listrow Each item placed vertically below the previous Stacked images; one item per line
tablerow Each item in a new row of a Word table Group question data in a structured table; one response per row

Quick guide

  • Use foreach when you want multiple images placed side by side in a row, or repeating values inline.
  • Use listrow when you want each image or item stacked vertically, one below the previous.
  • Use tablerow when you want repeating group question responses in a structured Word table with one row per response.

foreach

foreach loops through each item and places them horizontally, one after the previous. Items wrap to the next line when the available width is filled.

Use case: multiple images from an image question

Use foreach when an image question has Multiple ticked and you want the uploaded photos displayed side by side.

Screenshot 2025-03-25 at 3.06.03 PM.png

An image capture question (Q5) with Multiple ticked. The worker can upload more than one photo when submitting the form.

$id5 = the code for your image question from the Custom Printing panel

300 = image width in pixels. 0 = auto height (preserves aspect ratio)

{foreach from=$id5 item=_picture} {$_picture|insert_image:300:0} {/foreach}

Output: each photo uploaded by the worker is placed side by side in the PDF.

 

 

listrow

listrow loops through each item and places them vertically, one below the previous. Each image or value appears on its own line.

Use case: multiple images stacked vertically

Same syntax as foreach - only the tag name changes

{listrow from=$id5 item=_picture} {$_picture|insert_image:300:0} {/listrow}

Output: each photo uploaded by the worker is stacked vertically in the PDF.

 

 

tablerow

tablerow loops through each item and places it in a new row of a Word table. Use this for group question data where each response should appear as its own table row with columns aligned.

Required Word table setting

For tablerow to generate new rows automatically, you must enable a setting on your Word table.

  • In Microsoft Word: right-click the table, select Table Properties, go to the Row tab, and tick Allow row to break across pages.
    Without this setting, tablerow may not create new rows and all data may appear in a single cell.

Use case 1: group question with text data

Use tablerow to display responses from a group question with multiple answers enabled. Each response appears as a new row in the output table.

Screenshot 2025-03-25 at 3.04.48 PM.png

A Question Group (Q8) titled Work Done with Multiple answers ticked. It contains a Worker question (Name) and a Text Field (Work Done).

The tablerow code is split across your Word table cells, matching the column layout. The opening tag and first field go in the first column cell. The closing {/tablerow} goes at the end of the last column cell.

$id7 = the group question code

$_row.data.id1 = Worker Name field inside the group

$_row.data.id2 = Work Done field inside the group
 

First cell:   {tablerow from=$id7 item=_row}{$_row.data.id1}

Second cell:  {$_row.data.id2}{/tablerow}

Input:

Questions in Multiple Response Question Group
Name Work Done
{tablerow from=$id7 item=_row}{$_row.data.id1} {$_row.data.id2}{/tablerow}

 

Output:

Questions in Multiple Response Question Group
Name Work Done
Johnny Poured concrete
Billy Grinded sidewalk
Chad Laid conduit

Input template (top): the tablerow code split across two cells. Output (bottom): each group response generates a new table row with the worker name and work done.


Use case 2: single image per group response

When each group response contains a single image (Multiple NOT ticked on the image question), use tablerow with the insert_image syntax for the image field.

A Question Group (Q7) with Multiple answers ticked on the group. The Image Capture question inside has Multiple NOT ticked, so each response captures one photo.

$id7 = the group question code

$_row.data.id2 = description text field inside the group

$_row.data.id1|insert_image:300:0 = single image field inside the group
 

First cell:   {tablerow from=$id7 item=_row}{$_row.data.id2}

Second cell:  {$_row.data.id1|insert_image:300:0} {/tablerow}

 

Input:

Images in Multiple Response Group Questions
{tablerow from=$id7 item=_row}{$_row.data.id2} {$_row.data.id1|insert_image:300:0} {/tablerow}

Output:

Images in Multiple Response Group Questions
Morning concrete work (1/2).

Afternoon concrete work (2/2).

Input template (top): description in the first cell, single image in the second cell. Output (bottom): each group response generates a new row with one image per row.


Use case 3: multiple images per group response

When each group response contains multiple images (Multiple ticked on the image question inside the group), nest foreach inside tablerow to loop through all images within each response.

A Question Group (Q7) with Multiple answers ticked on the group. The Image Capture question inside has Multiple NOT ticked, so each response captures one photo.

$id7 = the group question code

$_row.data.id2 = description text field inside the group

$_row.data.id5 = image field inside the group (Multiple ticked)
 

First cell:   {tablerow from=$id7 item=_row}{$_row.data.id2}

Second cell:  {foreach from=$_row.data.id5 item=_picture} {$_picture|insert_image:150:0} {/foreach}{/tablerow}

Input:

Multiple Images in Multiple Response Group Questions
{tablerow from=$id7 item=_row}{$_row.data.id2} {foreach from=$_row.data.id5 item=_picture} {$_picture|insert_image:150:0} {/foreach}{/tablerow}

Output:

Multiple Images in Multiple Response Group Questions
Morning concrete work (1/2).

Afternoon concrete work (2/2).

Input template (top): description in the first cell, nested foreach for multiple images in the second cell. Output (bottom): morning concrete work shows 2 images side by side; afternoon shows 2 side by side

The nested foreach inside tablerow places all images from a single group response side by side in the image cell. A new tablerow is generated for each group response.
 

Things to know

  • tablerow requires a Word table setting to be enabled. Right-click the table, go to Table Properties, Row tab, and tick Allow row to break across pages.
  • The tablerow code must be split across your Word table cells. The opening tag goes in the first cell. The closing {/tablerow} goes at the end of the last cell.
  • For images inside a group question, whether you use the single image syntax or nested foreach depends on whether Multiple is ticked on the image question inside the group.
  • foreach, listrow, and tablerow all use the same from= syntax. The difference is only in how the output is laid out.
  • Closing tags must match: {foreach}...{/foreach}, {listrow}...{/listrow}, {tablerow}...{/tablerow}.

Was this article helpful?

0 out of 0 found this helpful