---
title: "Conditionally remove table rows"
description: "Generate tables that dynamically include or exclude rows based on data conditions, allowing customised content to appear only when specific criteria are met."
canonical_url: "https://resources.docmosis.com/template-tutorials/conditional-rows"
last_reviewed: 2026-06-12
---

# Conditionally remove table rows

Use the conditional rows \<\\>

marks the beginning of a set of rows to be optionally filtered out. 

The end marker is placed in a row further down the table:

\<\\>

If the data value book1 is true, all rows between the \<\\> row and the \<\\> row will be included.  The rows containing the \<\\> and \<\\> are always removed.

### Conditional rows within repeating rows

There is no limitation to using conditional rows within tables. \
Conditional rows can be nested within other conditional rows or used within repeating rows.\
In the example template, because the \<\\> conditional row is positioned within the loop \<\\>, the conditional row will be tested for each data item in newspapers, and each one that have inStock equal to true will be included.

### Conditional rows and expressions

Expressions may be used in the conditional field in order to test more complex conditions.\
They are included in braces and cause the rows between to be included if true.\
The rows between the \<\\> and the \<\\> are only included if the "description" of a particular "newspapers" is present (i.e. not equal to null) and is not blank.

# Conditionally remove table rows - related json data

```json
{
  "book1": true,
  "book2": false,
  "book3": true,
  "newspapers": [
    {
      "name": "The Wall Street Journal",
      "description": "International daily newspaper based in New York City",
      "inStock": true,
      "count": 3
    },
    {
      "name": "The New York Times",
      "description": "American newspaper based in New York City read worldwide",
      "inStock": true,
      "count": 10
    },
    {
      "name": "USA Today",
      "description": "Internationally distributed American daily newspaper",
      "inStock": false,
      "count": 0
    },
    {
      "name": "Los Angeles Times",
      "description": "",
      "inStock": true,
      "count": 4
    },
    {
      "name": "San Jose Mercury News",
      "description": "American daily newspaper published in San Jose, California",
      "inStock": false,
      "count": 0
    }
  ]
}
```

# Conditionally remove table rows - example template syntax

```docmosis
**Conditional Rows**

Table rows may be included or excluded from the final document – depending on the data.

\<\\> | This row is always removed |
| The Adventures of Sherlock Holmes | This row is included as book1 is true |
| \<\\> | This row is always removed |
|  |  |
| \<\\> | This row is always removed |
| Treasure Island | This row is removed as book2 is false |
| \<\\> | This row is always removed |
|  |  |
| \<\\> | This row is always removed |
| Peter Pan | This row is included as book3 is true |
| \<\\> | This row is always removed |

The row with Treasure Island has been removed as the data “book2” is false.

**Conditional Rows and Repeating Rows**

When filling tables with data, you may choose to only include some of the rows based on an expression or condition.

This may be done by nesting a \<\\> |  |
| \<\\> |  |
| \<\\> | This row is only included when “inStock” is true |
| \<\\> |  |
| \<\\> |  |

**Conditional Rows and Expressions**

More complex expressions may be used with the \<\\> |  |
| \<\\> |  |
| \<\\> | \<\\> |
| \<\\> |  |
| \<\\> |  |

Some rows may always be included, while others may be conditional as follows:

A description is only included for examples where “description” is in the data.

| **Newspaper Details:** |  |
| --- | --- |
| \<\\> |  |
|  | |
| \<\\> | \<\\> |
| \<\\> |  |
| *\<\\>* | |
| \<\\> |  |
| \<\\> |  |

This table only shows the first 3 rows of information by testing the built\-in $rownum variable:

| **Top 3 Newspapers:** |
| --- |
| \<\\> |
| \<\\> |
| \<\<$rownum\>\> \<\\> |
| \<\\> |
| \<\\> |
```