Last modified: August 22, 2025
In order to expand the logic and functionality of your templates, HubL supports several key operators and expression tests. The operators allow you to execute math functions, make comparisons, complicate template logic, and alter what markup renders. In addition, this article contains a comprehensive list of expression tests that can be used in HubL.

Operators

Operators are symbols that tell the HubL compiler to execute various operations that result in the final output. Operators are placed between operands in order to relate the two values, whether for executing math functions, making comparisons, or implementing boolean expressions.
operators-and-operands-diagram
Below are the operators you can use in HubL, organized by type.

Math

Standard math operators can be used to calculate values in the context of a template.
{% set my_num = 11 %}
{% set my_number = 2 %}

{{ my_num + my_number }}
<!-- 11 + 2 = 13 -->

{{ my_num - my_number }}
<!-- 11 - 2 = 9 -->

{{ my_num / my_number }}
<!-- 11 / 2 = 5.5 -->

{{ my_num % my_number }}
<!-- 11 % 2 = 1 -->

{{ my_num // my_number }}
<!-- 11 // 2 = 5 -->

{{ my_num * my_number }}
<!-- 11 * 2 = 22 -->

{{ my_num ** my_number }}
<!-- 11 ** 2 = 121 -->
SymbolDescription
+Adds two objects together, generally number values. To concatenate strings or lists, you should use the ~ operator instead.
-Subtracts one number from another.
/Divides numbers.
%Returns the remainder from dividing numbers.
//Divide two numbers and return the truncated integer result. For example, {{ 20 // 7 }} is 2.
*Multiplies numbers.
**Raise the left operand to the power of the right operand.

Comparison

Comparison operators can be used to evaluate values for template logic. You can see some examples of comparison operators being used in if statements.
{% set my_num = 11 %}
{% set my_number = 2 %}

{{ my_num == my_number }}
<!-- Evaluates to false -->

{{ my_num != my_number }}
<!-- Evaluates to true -->

{{ my_num > my_number }}
<!-- Evaluates to true -->

{{ my_num >= my_number }}
<!-- Evaluates to true -->

{{ my_num < my_number }}
<!-- Evaluates to false -->

{{ my_num <= my_number }}
<!-- Evaluates to false -->
SymbolshorthandDescription
==eqEqual to. Evaluates to true if the two objects have equal values.
!=neNot equal to. Evaluates to true if the two objects are not equal.
>gtGreater than. Evaluates to true if the left operand value is greater than the right operand.
>=gteGreater than or equal to. Evaluates to true if the left operand is greater or equal to the right operand.
<ltLess than. Evaluates to true if the left operand is lower than the right operand.
<=lteLess than or equal to. Evaluates to true if the left operand is lower or equal to the right operand.
The shorthand version of the comparison operators are usable in HubL filters that involve testing an expression such as |selectattr().

Logical

Logical operators allow you to implement boolean expressions, as well as combine multiple expressions into single statements.
Two non-empty strings:
{{ "a" and "b" }}
<!-- Evaluates to true -->

Empty string and non-empty string:
{{ "" and "b" }}
<!-- Evaluates to false -->

Two non-zero numbers:
{{ 1 and 2 }}
<!-- Evaluates to true -->

Zero and non-zero number:
{{ 0 and 1 }}
<!-- Evaluates to false -->

Two non-empty lists:
{{ [1] and [2] }}
<!-- Evaluates to true -->

Empty list and non-empty list:
{{ [] and [2] }}
<!-- Evaluates to false -->

Two non-empty dicts:
{{ {a: 1} and {b: 2} }}
<!-- Evaluates to true -->

Empty dict and non-empty dict:
{{ {} and {b: 2} }}
<!-- Evaluates to false -->
SymbolDescription
andReturns true if both the left and right operand are truthy. Otherwise, returns false.

This operator does not behave like the and operator in Python or the && operator in JavaScript. Learn more about using and operators below.
orReturns the first operand if it is truthy. Otherwise, returns the second operand.

This operator is equivalent to or in Python and || in JavaScript. Learn more about using or operators below.
isJoins two operands for an affirmative statement.
notNegates a statement, in conjunction with is.
(expr)Group an expression for the order of operations. For example, (10 - 2) * variable.
?The ternary operator can be used to quickly write conditional logic. Accepts 3 arguments: expression, true condition, false condition. Evaluates an expression and returns the corresponding condition.
Using and/or operators In HubL, the or operator behaves like the or operator in Python and the || operator in JavaScript. It will return the first operand if the expression evaluates as true, otherwise it will return the second operand. A common use case for the or operator is setting a fallback value when a variable value isn’t defined.
Two non-empty strings:
{{ "a" or "b" }}
<!-- Evaluates to "a" -->

Empty string and non-empty string:
{{ "" or "b" }}
<!-- Evaluates to "b" -->

Defining a fallback value:
{{ some_variable or "default value" }}
<!-- If some_variable is defined, print its value,
otherwise print "default value" -->
However, the and operator behaves differently than the and operator in Python and the && operator in JavaScript. In HubL, and will always return a boolean value: when the expression evaluates as true, true is returned, otherwise it will return false. The Python and JavaScript operators, on the other hand, will return an operand value based on whether the statement evaluates as true or false.
Two non-empty strings:
{{ "a" and "b" }}
<!-- Evaluates to true -->

Empty string and non-empty string:
{{ "" and "b" }}
<!-- Evaluates to false -->
In HubL, empty lists ([]) and empty dicts ({}) are considered falsy. This is equivalent to the behavior in Python, but different from JavaScript, where [] and {} are truthy.
Empty list and non-empty list:
{{ [] or [2] }}
<!-- Evaluates to [2] -->

Empty dict and non-empty dict:
{{ {} and {b: 2} }}
<!-- Evaluates to false -->

Other HubL operators

Below are other important HubL operators that can be used to perform various tasks.
SymbolDescription
inChecks to see if a value is in a sequence.
isPerforms an expression test.
|Applies a filter.
~Concatenates values.

Expression tests

Expression tests are various boolean conditions that can be evaluated by using logical operators.

boolean

Tests whether the object is boolean (in a strict sense, not in its ability to evaluate to a truthy expression).
{% set isActive = false %}

{% if isActive is boolean %}
isActive is a boolean
{% endif %}

containing

Tests whether a list variable has a value in it.
{% set numbers = [1, 2, 3] %}

{% if numbers is containing 2 %}
Set contains 2!
{% endif %}

containingall

Tests if a list variable contains all of the values of another list.
{% set numbers = [1, 2, 3] %}

{% if numbers is containingall [2, 3] %}
Set contains 2 and 3!
{% endif %}

{% if numbers is containingall [2, 4] %}
Set contains 2 and 4!
{% endif %}

defined

Tests whether a variable is defined within the context of the template. While you can use this expression test, writing an if statement without any operators will default to checking whether or not the variable is defined. In the example below, a color module’s color parameter is tested. If the color parameter had no value, the template would render a default black background color. If it is defined, it renders the background color set by the user.
{% color "my_color" color="#930101", export_to_template_context=True %}
<style>
{% if widget_data.my_color.color is defined %}
body{
background: {{ widget_data.my_color.color }};
}
{% else %}
body{
background: #000;
}
{% endif %}
</style>

divisibleby

Tests whether an object is divisible by another number. For example, below a for loop is created that iterates through a list of types of animals. Each type of animal gets printed in a div, and every 5th div has different inline styling applied (width:100%). This concept could be applied to a blog where different markup is rendered for a certain pattern of posts. To learn more about for loops and loop.index, check out this article.
{% set animals = ["lions", "tigers", "bears", "dogs", "sharks"] %}
{% for animal in animals %}
{% if loop.index is divisibleby 5 %}
<div style="width:100%">{{animal}}</div>
{% else %}
<div style="width:25%">{{animal}}</div>
{% endif %}
{% endfor %}

equalto

Tests whether a variable’s value is equal to a constant or another variable. You can also use the operator == to do the same test. In the example below, the width of the blog posts is adjusted based on the total number of posts in the loop. The example output assumes there were 4 posts in the blog.
{% for content in contents %}
{% if loop.length is equalto 2 %}
<div style="width:50%;">Post content</div>
{% elif loop.length is equalto 3 %}
<div style="width:33.333332%;">Post content</div>
{% elif loop.length is equalto 4 %}
<div style="width:25%;">Post content</div>
{% else %}
<div style="width:100%;>Post content</div>
{% endif %}
{% endfor %}

even

Tests whether a numeric variable is an even number. The example below shows a simplified blog listing loop, where if the current iteration of the loop is even, a class of even-post is assigned to the post item div. Otherwise, a class of odd-post is assigned.
{% for content in contents %}
{% if loop.index is even %}
<div class="post-item even-post">Post content</div>
{% else %}
<div class="post-item odd-post">Post content</div>
{% endif %}
{% endfor %}

float

Tests whether a numeric variable is a floating-point number.
{% set quantity = 1.20 %}
{% if quantity is float %}
quantity is a floating point number
{% endif %}

integer

Tests whether a variable is an integer.
{% set quantity = 120 %}
{% if quantity is integer %}
Quantity is an integer
{% endif %}

iterable

Tests whether a variable can be looped through. This example checks a variable called jobs to see if it can be iterated through. Since the variable contains a list of jobs, the if statement would evaluate to true, and the loop would run. If the variable had contained a single value, the if statement would print that value with different markup instead. Learn more about for loops.
{% set jobs = ["Accountant", "Developer", "Manager", "Marketing", "Support"] %}

{% if jobs is iterable %}
<h3>Available positions</h3>
<ul>
{% for job in jobs %}
<li>{{ job }}</li>
{% endfor %}
</ul>
{% else %}
<h3>Available position</h3>
<div class="single-position">{{ jobs }}</div>
{% endif %}

lower

Tests whether a string is lowercase. The example below uses an unless statement and a lower filter to ensure that a string of text entered into a text module is always lowercase.
{% module "my_text" path="@hubspot/text" label="Enter text", value="Some TEXT that should be Lowercase", export_to_template_context=True %}

{% unless widget_data.my_text.value is lower %}
{{ widget_data.my_text.value|lower }}
{% endunless %}

mapping

Tests whether an object is a dict (dictionary). The example below is checking to see if the contact object is a dictionary.
{% if contact is mapping %}
This object is a dictionary.
{% else %}
This object is not a dictionary.
{% endif %}

none

Tests whether a variable has a null value.
{% module "user_email" path="@hubspot/text" label="Enter user email", value="example@hubspot.com", export_to_template_context=True %}
{% unless widget_data.user_email.value is none %}
{{ widget_data.user_email.value }}
{% endunless %}

number

Tests whether the value of a variable is a number. The example below checks a variable to see whether or not it is a variable, and if so it converts it into millions.
{% set my_var = 40 %}
{% if my_var is number %}
{{ my_var * 1000000 }}
{% else %}
my_var is not a number.
{% endif %}

odd

Tests whether a numeric variable is an odd number. Below is the same example as the inverse even expression test previously described.
{% for content in contents %}
{% if loop.index is odd %}
<div class="post-item odd-post">Post content</div>
{% else %}
<div class="post-item even-post">Post content</div>
{% endif %}
{% endfor %}

sameas

Tests whether or not two variables have the same value. The example below sets two variables and then checks to see whether or not they are the same.
{% set var_one = True %}
{% set var_two = True %}
{% if var_one is sameas var_two  %}
The variables values are the same.
{% else %}
The variables values are different.
{% endif %}

sequence

Similar to the iterable test, this expression test checks whether a variable is a sequence. The example below tests whether a variable is a sequence, then iterates through that sequence of musical genres.
{% set genres = ["Pop", "Rock", "Disco", "Funk", "Folk", "Metal", "Jazz", "Country", "Hip-Hop", "Classical", "Soul", "Electronica" ] %}
{% if genres is sequence %}
<h3>Favorite genres</h3>
<ul>
{% for genre in genres %}
<li>{{ genre }}</li>
{% endfor %}
</ul>
{% else %}
<h3>Favorite genre:</h3>
<div class="single-genre">{{ genres }}</div>
{% endif %}

string

Tests whether the value stored in a variable is text. The example below checks whether a variable is a string, and if so it applies a title filter to change the capitalization.
{% set my_var = "title of section" %}
{% if my_var is string %}
{{ my_var|title }}
{% else %}
my_var is not a string
{% endif %}

string_containing

Tests whether a provided substring is contained within another string. This expression test is used in conjunction with the is operator.
{% if content.domain is string_containing ".es" %}
Markup that will only render on content hosted on .es domains
{% elif content.domain is string_containing ".jp" %}
Markup that will only render on content hosted on .jp domains
{% else %}
Markup that will render on all other domains
{% endif %}

string_startingwith

Tests whether a string starts with a particular string. It is used in conjunction with the is operator.
{% if content.slug is string_startingwith "es/" %}
Markup that will only render on content hosted in a /es/ subdirectory
{% elif content.slug is string_startingwith "jp/" %}
Markup that will only render on content hosted in a /jp/ subdirectory
{% else %}
Markup that will render on all subdirectories
{% endif %}

truthy

Tests whether an expression evaluates to True. The example below uses a boolean checkbox module to display an alert message.
{% boolean "check_box" label="Show alert", value=True, export_to_template_context=True %}

{% if widget_data.check_box.value is truthy %}
<div class="alert">Danger!</div>
{% endif %}

undefined

Tests whether a variable is undefined in the context of the template. This test is different from the none expression test in that undefined will be true when the variable is present but has no value; whereas, none will be true when the variable has a null value. The example below checks a template for the existence of the variable “my_var”.
{% if my_var is undefined %}
A variable named "my_var" does not exist on this template.
{% else %}
{{ my_var }}
{% endif %}

upper

Tests whether a string is all uppercase. Below is an inverse example of the lower expression test above.
{% module "my_text" path="@hubspot/text" label="Enter text", value="Some TEXT that should be Uppercase", export_to_template_context=True %}

{% unless widget_data.my_text.value is upper %}
{{ widget_data.my_text.value|upper }}
{% endunless %}

within

Tests whether a variable is present within a list.
{% set numbers = [1, 2, 3] %}

{% if 2 is within numbers %}
2 is in the list!
{% endif %}

{% if 4 is within numbers %}
4 is in the list!
{% endif %}