---
title: "Expressions using boolean logic"
description: "Control template sections to appear or hide based on combined true/false conditions using AND, OR, and NOT logic for precise document output."
canonical_url: "https://resources.docmosis.com/template-tutorials/expressions-logic"
last_reviewed: 2026-06-12
---

# Expressions using boolean logic

This example introduces the notation used to perform simple logic calculations in the templates.
It explores how to call logic and boolean operators such as AND/OR within the template, which is most useful in [Conditional Sections](/template-tutorials/conditional-sections).
It is best to view the template and output images or files side-by-side to understand their functionality.

### Logical OR

The OR operator, represented by a double pipe "||", can be used with 2 or more fields or expressions.
**Example 1 :**
{sampleValue1||sampleValue2}
The OR operator evaluates if either sampleValue1 or sampleValue2 is true.
When used in a conditional section, the conditional section is shown if either value is true.
**Example 2 :**
{sampleValue3=’red’||sampleValue4=’red’}
In the expressions sampleValue3=’red', sampleValue4=’red' the "=" operator tests the values of sampleValue3 and sampleValue4 and returns true or false.
Then the OR operator evaluates whether either of the expressions have returned true.
When used in a conditional section, the conditional section is shown if either value is true.

### Logical AND

The AND operator, represented by a double ampersand "&&", can be used with 2 or more fields or expressions.
**Example 1 :**
{sampleValue1&&sampleValue2}
The AND operator evaluates if both sampleValue1 and sampleValue2 are true.
When used in a conditional section, the conditional section is shown if both values are true.
**Example 2 :**
{sampleValue3=’red’&&sampleValue4=’red’}
In the expressions sampleValue3=’red’,sampleValue4=’red' the "=" operator tests the values of sampleValue3 and sampleValue4 and returns true or false.
Then the AND operator evaluates whether both expressions have returned true.
When used in a conditional section, the conditional section is shown if both values are true.

### Logical NOT

The NOT operator, represented by an exclamation mark "!", can be used with one field or applied to an expression.
**Example 1 :**
!(sampleValue2)
The NOT operator inverses the value, i.e., if samplevelue1 is true, the expression !(sampleValue2)returns false.
When used in a conditional section, the conditional section is shown if value is false.
**Example 2 :**
!(sampleValue4=’red’)
In the expression sampleValue4=’red' the "=" evaluates the value of sampleValue4 and returns true or false.
Then NOT operator inverses the value. 
When used in a conditional section, the conditional section is shown if value is false.

### **Combining logical expressions**

(sampleValue3=’red’&&sampleValue4=’red’)||( sampleValue3=’green’&&sampleValue4=’green’)
In the expressions sampleValue3='red',sampleValue4='red',sampleValue3='green',sampleValue4='green'  the "=" evaluates the values of sampleValue3 and sampleValue4 and returns true or false.
Then the AND operator evaluates whether both expressions within a set of parentheses have returned true. i.e., both sampleValue3=’red’ and sampleValue4=’red’ have returned true.
Finally, the OR operator is used to combine these two sets of expressions. i.e., either (sampleValue3=’red’&&sampleValue4=’red’) or ( sampleValue3=’green’&&sampleValue4=’green’) is true.
When used in a conditional section, the conditional section is shown if sampleValue3 and sampleValue4 are both 'red', or are both 'green'.

## Expressions using boolean logic - related json data

```json
{
"sampleValue1": "true",
"sampleValue2": "false",
"sampleValue3": "red",
"sampleValue4": "green"
}
```

## Expressions using boolean logic - example template syntax

**Expressions – Logic**


**Data sent:**
sampleValue1: <<sampleValue1>>
sampleValue2: <<sampleValue2>>
sampleValue3: <<sampleValue3>>
sampleValue4: <<sampleValue4>>

**Logical OR**
<<cs_{sampleValue1||sampleValue2}>>
This line will show if sampleValue1 OR sampleValue2 is **TRUE**
<<es_>>

<<cs_{sampleValue3=’red’||sampleValue4=’red’}>>
This line will show if sampleValue3 OR sampleValue4 is **RED**
<<es_>>

**Logical AND**
<<cs_{sampleValue1&&sampleValue2}>>
This line will show only if sampleValue1 AND sampleValue2 are both are **TRUE**
<<else>>
EithersampleValue1 or sampleValue2 is **False**
<<es_>>

<<cs_{sampleValue3=’red’&&sampleValue4=’red’}>>
This line will show only if sampleValue3 AND sampleValue4 both are **RED**
<<else>>
EithersampleValue3 or sampleValue4 is **NOT RED**
<<es_>>

**Logical NOT**
<<cs_{ !(sampleValue2)}>>
This line will show if sampleValue2 is **False**
<<es_>>

<<cs_{sampleValue4!=’red’}>>
This line will show if sampleValue4 is **NOT** **RED**
<<es_>>

**Combining logical expressions**
<<cs_{(sampleValue3=’red’&&sampleValue4=’red’) ||( sampleValue3=’green’&&sampleValue4=’green’)}>>
This line will show if sampleValue3 AND sampleValue4 are **both RED** or **both GREEN**
<<else>>
Both sampleValue3 and sampleValue4 **both** are **NOT RED**, or **both** are **NOT GREEN**.
<<es_>>