Conditions and Loops
Last updated March 23, 2026
The builder’s Logic panel lets you control when elements appear and how they repeat. You can make any element conditional — visible only when a data condition is met — or repeat it once for each item in a collection. These two features cover the most common dynamic content patterns: showing or hiding sections based on context, and generating rows from a list of items.
The Logic panel
Select any element in the canvas (except the document root), then switch to the Settings tab in the right panel. The Logic section appears below the Element Info section, with two toggles: Visibility Condition and Repetition.
A small indigo dot appears next to the “Logic” heading when either feature is active on the selected element.
Visibility conditions
Toggle on Visibility Condition to make an element appear only when a condition is true. An input field appears where you enter a JavaScript expression evaluated against your document’s test data.

Writing conditions
The condition is a JavaScript expression that has access to your test data. Some examples:
| Condition | What it does |
|---|---|
customer.isPremium | Shows the element when the customer is premium |
items.length > 0 | Shows the element when the items array is not empty |
order.status === 'paid' | Shows the element when the order status is “paid” |
total >= 1000 | Shows the element when the total is 1,000 or more |
Live evaluation
The Logic panel evaluates your condition against the current test data in real time and shows the result:
- Green (“Element is currently visible”) — the condition evaluates to a truthy value with your current test data, so the element appears in the preview.
- Red (“Element is currently hidden”) — the condition evaluates to a falsy value, so the element is hidden in the preview.

If the condition contains a syntax error, a red error banner appears at the bottom of the builder.
A link to Edit test data appears below the status indicator, letting you quickly adjust your test data to try different scenarios.
Repetition
Toggle on Repetition to repeat an element once for each item in a collection from your test data. Two input fields appear:
- Collection — the path to an array in your test data (for example,
invoice.productsorusers) - Item name — the variable name for the current item in the loop (auto-suggested by singularizing the collection name)

How it works
When you enter a collection path like lineItems, the builder automatically suggests an item name of lineItem (the singular form). You can change this to any name you prefer.
The panel then shows a summary of what the loop does and lists the available variables:
| Variable | Description |
|---|---|
The item variable (e.g., lineItem) | The current item from the collection |
The index variable (e.g., lineItemIndex) | The zero-based position of the current item |
The panel also shows helper expressions you can copy for common checks:
- First item check:
lineItemIndex === 0 - Last item check:
lineItemIndex === lineItems.length - 1
Using loop variables in child elements
Child elements of a repeated element can reference the item and index variables. For example, if you repeat a container over lineItems with the item name lineItem, a Text block inside that container can display lineItem.name or lineItem.price using the variable browser.
Visibility and repetition are mutually exclusive
You cannot enable both Visibility Condition and Repetition on the same element. The builder enforces this — when one toggle is active, the other is disabled. This is because combining both on a single HTML element produces ambiguous behavior.
Workaround:
Combining with situational styling
Repeated elements work well with situational styling. Once an element repeats over a collection, you can apply different styles for odd and even items, highlight the first or last item, or show a fallback when the collection is empty. See the Situational Styling page for details.
Frequently asked questions
- How do I conditionally show or hide an element in PDFMonkey’s builder?
- Select the element, open the Settings tab, and toggle on Visibility Condition in the Logic section. Enter a JavaScript expression evaluated against your document data—for example, “customer.isPremium” or “items.length > 0”. The element only appears when the condition is truthy.
- How do I loop over a list of items in a PDFMonkey builder template?
- Select the element you want to repeat, open the Logic panel, and toggle on Repetition. Enter the path to an array in your data (e.g. “invoice.products”) as the Collection and choose an Item name. The builder repeats the element once for each item in the array.
- Can I use both visibility conditions and repetition on the same element?
- No. The builder only allows one at a time on a given element. To repeat elements and conditionally show some of them, nest a child element with a Visibility Condition inside a parent Container that has Repetition enabled.