Understanding @if/@else conditional logic

Modified on Thu, 4 Dec at 11:32 AM

Understanding @if/@else conditional logic

Conditional logic allows your templates to show or hide specific parts of a message based on the data on the lead.

On this page

Jump to any section using the links below

Conditional logic allows your templates to show or hide specific parts of a message based on the data on the lead. This makes your Email and SMS communication dynamic, personalized, and much more powerful.

Hubhus uses a simple but flexible logic language built directly into the template editor.


Use the Editor to test logic and find placeholders instantly

In any input field inside the editor, you can press:

  • CTRL + K (Windows)

  • CMD + K (Mac)

This opens the placeholder search modal, where you can quickly look up:

  • Lead placeholders (name, email, phone, address, etc.)

  • Event placeholders (date, time, ICS links, resource emails, duration, etc.)

  • HTML components (buttons, signatures, branding blocks)

  • Links to pages (@page[...])

  • Booking forms

  • Custom fields (API-based placeholders)

  • Assigned person & brand placeholders

You can search using natural words like:
“lead name”, “address”, “event date”, “signature”, “brand contact”.

Using this tool is the fastest and safest way to locate the correct placeholder and ensure your logic is valid.


Built-in reference examples inside the editor

At the bottom of the editor, you will find a full reference area with practical, copy/paste-klare eksempler, including:

  • Variables

  • For loops

  • Nested loops

  • JSON data examples

  • File examples

  • Calendar event examples

  • Campaign relations examples

  • Checklist examples

These examples are extremely useful when you want to test how logic behaves before using it in a live template.

Tip: “Under editor kan du også finde informationer om:”
Variables, For loops, JSON data examples, File examples, Calendar event examples, Campaign relations examples, Checklist examples.


Basic @if statement

Shows content only if the placeholder has a value:

@if(%assigned_person_name%) Your personal consultant is: %assigned_person_name% @endif

Important:

These non-empty values still count as false:
0, false, off, nej, no, n.

Everything else counts as true.


Basic @if / @else

@if(%assigned_person_name%) Your personal consultant is: %assigned_person_name% @else{ You do not have a personal consultant yet. }@endif

Nested statements

@if(%assigned_person_name%) Your consultant is: %assigned_person_name% @if(%assigned_person_phone%) You can call %assigned_person_firstname% at: %assigned_person_phone% @endif @else{ You do not have a personal consultant yet. }@endif

Comparison operators

You can compare values using:

  • == equal

  • != not equal

  • ~= contains (case-insensitive)

  • <, <=, >, >=

  • Logical operators: && and ||

Examples

Numeric or field comparison:

@if({{postnr}} >= 6000) For support in Jutland please call: +45 12 34 12 34 @endif

Date comparison:

@if(%lead_created_at% < @str2datetime[-2 weeks]) Lead is more than 2 weeks old @endif

Text comparison:

@if(%assigned_person_name% == Henrik Omdal) You are assigned to our coding expert :) @endif

Contains check (~=)

Case-insensitive substring search:

@if(%lead_company% ~= A/S) Company contains "A/S" @endif
@if(%lead_email% ~= @example.com) Email belongs to example.com @endif

Logical operators (&& and ||)

OR example

@if(%lead_company% == Company A || %lead_company% == Company B) Lead is from either A or B @endif

AND example

@if(%lead_company% == Company A && %assigned_person_email% == ho@hubhus.com) Valid combination @endif

Important:

Parentheses are NOT supported.
If both operators are used, || is evaluated before &&.


Best practices

  • Use slugs, not labels, for select-field comparisons

  • Use @else for fallback content

  • Keep logic simple and readable

  • Always test conditions with real leads

  • Use the CTRL+K / CMD+K modal to avoid placeholder mistakes

  • Look at the editor’s built-in examples when constructing loops or variables


Learning outcome

After reading this, you should understand:

  • How conditional logic works in Hubhus

  • How to use @if, @else, and @elseif

  • How to compare values safely

  • How to use contains, numeric, and text logic

  • How to troubleshoot unexpected behavior

  • How to use the editor’s built-in tools (CTRL+K / CMD+K + examples)

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article