Skip to main content

Syntax

Expression Language uses JavaScript-like syntax designed to be intuitive for both designers and developers. Optimized for visual development workflows. Understanding these syntax rules is essential for writing valid expressions that transform and process your WordPress data effectively across all Builderius contexts.

Basic Expression Structure

All expressions follow consistent syntax patterns:

Context-Specific Wrappers

  • Element Content, Attributes & Component Properties: [[expression]] - Same like dynamic data access
  • Loop Content: {{expression}} - Current loop item data
  • GraphQL Queries: expression_result(expression: "...") - No wrapper needed
  • Condition Builder: Raw expression - No wrapper needed

Single-Line Requirement

# Correct - single line
[[upper(limit_characters(post_title, 50, '...')]]

# Error - multiple lines not allowed
[[upper(
limit_characters(post_title, 50, '...')
)]]

Data Access Syntax

Expressions use "dot notation" to access dynamic data. If the field is a sibling to the expression, then a simple field_name is used, if the sibling sub-field should be selected field_name.sub_fieldname is used, and if the field is in another scope full path should be used, for eg. wp.post.title.

Access TypeSyntaxExampleDescription
Field Accessfield_namepost_titleDirect field reference
object.propertycurrent_user.display_nameObject property access
wp.scope.fieldwp.post.post_titleWordPress context data
Array Accessarray[index]posts[0]First array item
array[index].fieldcategories[1].nameArray item property
wp.query.array[0].fieldwp.posts_query.posts[0].post_titleWordPress array data
Object Propertiesparent.child.grandchildpost_author.display_nameNested property access
complex.nested.pathfeatured_image.alt_textDeep object nesting
wp.context.nested.datawp.archive.term.parent.nameWordPress nested data

Function Call Syntax

Functions transform and process data using parentheses syntax function_name(arguments). Functions can be nested inside other functions, and arguments can be literal values, variables, or other function results.

Function TypeSyntaxExampleDescription
Simple Functionsfunction()time()No arguments needed
function(value)upper('hello world')Single argument
function(variable)count(posts)Variable as argument
Multiple Argumentsfunction(arg1, arg2)limit_words(post_content, 25)Two arguments
function(arg1, arg2, arg3)limit_words(text, 25, '...')Three arguments
function(string, number, boolean)has_term('featured', 'category', post_id)Mixed argument types
Nested Functionsouter(inner(value))upper(limit_words(post_title, 5))Function as argument
function(nested(args), value)sprintf('$%.2f', round(price, 2))Mixed nested and direct
complex(nested(chain()))join(sort(split(tags_string, ',')), ' • ')Multiple nesting levels

Data Types and Values

Expressions work with different data types that represent various kinds of information. String values must be quoted, numbers are written directly, and arrays use square brackets. Understanding data types ensures your expressions process values correctly.

Data TypeSyntaxExampleUsage
Strings'text' or "text"'Hello World'Text values, must be quoted
'escaped\'quote''It\'s working'Escape quotes inside strings
variable ~ ' text'first_name ~ ' ' ~ last_nameString concatenation
Numbers12345.67Integers and decimals
-100Negative and zero values
price + taxquantity * unit_priceMathematical operations
Booleanstrue or falseis_logged_inTrue/false values
expression > valuecount(posts) > 0Boolean expressions
function()is_user_logged_in()Boolean-returning functions
Arrays[item1, item2][1, 2, 3, 4, 5]Lists of values
['text', 'values']['apple', 'banana', 'orange']String arrays
variable[index]posts[0]Array item access

Operators

Operators combine and compare values to create logical expressions. Use comparison operators to test conditions, logical operators to combine multiple conditions, and arithmetic operators for calculations. String concatenation joins text values together.

Operator CategoryUsage PatternExamplePurpose
Comparisonvalue operator valueprice == 100Test equality
variable != valuepost_status != 'draft'Test inequality
number > thresholdquantity > 5Numeric comparisons
Logicalcondition and conditionis_logged_in and has_permissionCombine conditions with AND
condition or conditionis_admin or is_editorCombine conditions with OR
not conditionnot is_guestNegate condition
Arithmeticnumber + numberbase_price + shippingMathematical operations
(expression) operator value(price * quantity) + taxUse parentheses for order
variable ** powerbase_amount ** growth_rateExponentiation
Stringtext ~ textfirst_name ~ ' ' ~ last_nameJoin strings together
prefix ~ variable ~ suffix'Hello, ' ~ user_name ~ '!'Build dynamic text
expression ~ stringcount(items) ~ ' items found'Combine values and text

Conditional Logic

Conditional logic enables decision-making in expressions using ternary operators for if/then/else logic and null coalescing for fallback values. These patterns let expressions adapt their output based on data conditions.

The condition ? true_value : false_value pattern provides if/then/else logic:

# Check user login status and display appropriate greeting
is_logged_in ? 'Welcome back!' : 'Please log in'

# Compare price value and assign category label
price > 100 ? 'Premium' : 'Standard'

# Nested conditional logic to determine user role display text
user_role == 'admin' ? 'Administrator' : (user_role == 'editor' ? 'Editor' : 'User')

# Multiple conditions with string concatenation for product availability
(inventory > 0) and (price > 0) ? 'Available - $' ~ price : 'Out of Stock'

Advanced Syntax Patterns

Arrow Functions

Arrow functions use the pattern (parameter) -> expression for array processing functions:

# Filter posts array to only include items with 'publish' status
filter(posts, (post) -> post.post_status == 'publish')

# Extract only the name property from each category object into a new array
foreach(categories, (cat) -> cat.name)

# Filter products that meet both price and inventory requirements
filter(products, (item) -> item.price > 50 and item.inventory > 0)

WordPress Data Integration

Access WordPress data through the wp context:

# Template context data
wp.post.post_title # Current post data
wp.current_user.display_name # Current user data
wp.archive.title # Archive context
wp.option_value__site_name # WordPress options

# Conditional WordPress data
wp.post ? wp.post.post_title : wp.archive.title
wp.current_user.ID ? 'Logged in' : 'Guest user'

Common Syntax Errors

String values must be quoted:

# Error - missing quotes
upper(hello world)
post_status == publish

# Correct - with quotes
upper('hello world')
post_status == 'publish'

Variable references don't use quotes:

# Error - quoted variable names
upper('post_title') # Treats as literal string "post_title"
count('posts') # Treats as literal string "posts"

# Correct - unquoted variables
upper(post_title) # Uses actual post_title value
count(posts) # Uses actual posts array

Syntax Best Practices

Readability

# Good - clear and readable
user_role == 'admin' ? 'Administrator Panel' : 'User Dashboard'

# Harder to read - no spaces
user_role=='admin'?'Administrator Panel':'User Dashboard'

Function Organization

# Good - logical grouping
upper(limit_words(post_title, 5))

# Confusing - unclear order
limit_words(upper(post_title), 5) # Uppercases first, then truncates

Variable Naming

# Good - descriptive field names  
is_user_logged_in()
post_author.display_name

# Less clear - abbreviated names
is_logged()
author.name
Complete Function Reference

For detailed information about all available functions, see: Built-in Functions → - Complete function library with examples and usage patterns

Operators Guide

For comprehensive operator documentation, see: Operators → - All comparison, logical, and mathematical operators

These syntax rules provide the foundation for writing valid Expression Language code across all Builderius contexts. Master these patterns, and you'll be able to create sophisticated data transformations and conditional logic throughout your templates.