Milk Admin

Expression Syntax

The syntax is the same in frontend and backend. Expressions work with numbers, strings, dates and booleans.

Parameters and fields

To read a value from the form or record use the syntax [field]:

[qty] * [price]
IF [type] == "company" THEN "Y" ELSE "N" ENDIF
Frontend: parameters are read from form fields (id, name or data[field]).
Backend: parameters come from the record array (Model field keys).

Operators

Category Operators Example
Mathematical + - * / % ^ [qty] * [price]
Comparison == != <> < > <= >= [start] <= [end]
Logical AND OR NOT (also && || !) [a] > 0 AND [b] > 0
Assignment = x = 5

Strings and dates

  • Strings with single or double quotes: "test", 'test'
  • Supported dates: YYYY-MM-DD and DD/MM/YYYY
  • Date operations: date + days, date - date (returns days)

IF / THEN / ELSE

IF [country] == "IT" THEN "IVA" ELSE "VAT" ENDIF

Available Functions

Functions are identical in PHP and JS:

  • NOW()
  • AGE(date)
  • ROUND(n, decimals)
  • ABS(n)
  • IFNULL(val, default)
  • UPPER(str)
  • LOWER(str)
  • CONCAT(str1, str2, ...)
  • TRIM(str)
  • ISEMPTY(val)
  • PRECISION(n, decimals)
  • DATEONLY(datetime)
  • TIMEADD(time, minutes)
  • ADDMINUTES(time, minutes)

TIMEADD / ADDMINUTES

They are aliases. Input can be a time string (HH:MM or HH:MM:SS) or a Date/DateTime. The output keeps the same format as the input (if seconds were present, they are preserved). Minutes can be negative and the result wraps on 24h.

TIMEADD([start_time], 45)
ADDMINUTES([start_time], -30)

Quick Examples

ROUND([total] * 0.22, 2)
IF ISEMPTY([discount]) THEN 0 ELSE [discount] ENDIF
DATEONLY(NOW())
Loading...