Skip to main content

Boolean Functions

Boolean functions help you validate data and make smart decisions in your templates. Instead of displaying broken content or causing errors, these functions let you check if data is valid, complete, and safe to use before showing it to users.

Why Boolean Functions Matter

Data validation challenges:

  • User input that might be invalid email addresses
  • Custom fields that could be empty or missing
  • URLs that might be malformed or broken
  • Numbers that could actually be text strings

What boolean functions solve:

  • Input validation: Check emails before displaying contact forms
  • Content safety: Verify URLs before creating links
  • Conditional display: Show content only when data exists
  • Error prevention: Validate data types before calculations

Data Type Checking

Verify that your data is the correct type before using it in calculations or displays.

is_numeric

Essential for validating prices, quantities, and any numeric input before calculations.

is_numeric(value)

When to use:

  • Validate product prices before formatting
  • Check user input quantities
  • Verify numeric custom fields before calculations

is_int

Perfect for validating counts, IDs, and anything that must be a whole number.

is_int(value)

When to use:

  • Validate user IDs and post IDs
  • Check quantity inputs (no half items)
  • Verify array indices and counters

is_float

Verify that prices, ratings, and measurements are proper decimal numbers.

is_float(value)

When to use:

  • Validate decimal prices and measurements
  • Check rating values with decimals
  • Verify percentage calculations

Content Validation

Check if user input and content follows expected formats.

is_email

Ensure email addresses are properly formatted before displaying or processing them.

is_email(string)

Alias: isEmail

When to use:

  • Validate contact form submissions
  • Check user profile email addresses
  • Verify author email fields before display

is_url

Check if URLs are properly formatted before creating links or displaying them.

is_url(string)

When to use:

  • Validate website URLs before creating links
  • Check social media profile links
  • Verify custom field URLs before display

Empty and Null Checking

Verify that required data exists before trying to display or use it.

is_empty

Determine if fields contain actual content or are empty/null.

is_empty(value)

When to use:

  • Check if required fields are filled
  • Validate form submissions
  • Determine if optional content should display

Common Validation Patterns

Safe Email Display

# Only show email if it's valid
is_email(contact_email) ? contact_email : 'Email not available'

# Create safe mailto link
is_email(user_email) ? 'mailto:' ~ user_email : '#'
# Only create link if URL is valid
is_url(website_url) ? '<a href="' ~ website_url ~ '">Visit Website</a>' : 'Website URL not available'

# Safe external link
is_url(external_link) and not is_empty(external_link) ? external_link : '/contact'