Frontend Macros Filters - Crocoblock/jetformbuilder GitHub Wiki
Table of Contents
Introduction
The filters listed below work on one main principle: take a value from a macro -> return the changed value.
Some filters may support an argument, such as ifEmpty
, and some may not, such as length
.
Here are some examples of their application:
%login|length%
- Getting the length of a value from thelogin
field;%login|ifEmpty(empty)%
- Getting the value from the login field. If it is empty, then we get the value "empty";%date_field|addDay(5)|addHour(3)|toDate%
- Getting the value from the date field -> adding 5 days -> adding 3 hours -> formatting the timestamp to the value for the Date Field;
Filters
ifEmpty
If the macro returns an empty value, the filter will return the value passed in the argument
Arguments
Any argument, except for the parentheses (
and )
Example
Macro string:
Value from field is: %field_name|isEmpty(empty)%
Result if field_name
is empty:
Value from field is: empty
Result if field_name
is filled with value "123"
Value from field is: 123
length
Returns the length of the string or array
Example
Macro string:
Number of charatcers from field is: %field_name|length%
Result if field_name
is filled with value "123"
Number of charatcers from field is: 3
T
Returns the time stamp. Usually used in conjunction with Date & Datetime and Time Field.
Example
For Date Field
%date_field|T%
Result if date_field
is filled with value "2022-10-22"
1666386000000
For Datetime Field
%datetime_field|T%
Result if datetime_field
is filled with value "2022-10-22T17:49"
1666450140000
For Time Field
%time_field|T%
Result if time_field
is filled with value "17:49" and today is 2022-10-22. (Today's date is taken as a basis.)
1666018173371
toDate
Gets a timestamp from the macro and formats it according to the Date field format
Example
https://github.com/Crocoblock/jetformbuilder/wiki/Frontend-Macros---External-Macros#ctcurrentdate
toDateTime
Gets a timestamp from the macro and formats it according to the Datetime field format
Example
https://github.com/Crocoblock/jetformbuilder/wiki/Frontend-Macros---External-Macros#ctcurrentdate
toTime
Gets a timestamp from the macro and formats it according to the Time field format
Example
https://github.com/Crocoblock/jetformbuilder/wiki/Frontend-Macros---External-Macros#ctcurrentdate
addMin
Adds minutes via an argument to a macro that returns a date or timestamp
Arguments
Integer only. If no argument is passed, the filter will add 1 minute
Example
Macro string:
%datetime_field|addMin(5)%
Result if datetime_field
is filled with value "2022-10-22T17:49"
1666450440000
addHour
Adds hours via an argument to a macro that returns a date or timestamp
Arguments
Integer only. If no argument is passed, the filter will add 1 hour
Example
Macro string:
%datetime_field|addHour(5)%
Result if datetime_field
is filled with value "2022-10-22T17:49"
1666468140000
addDay
Adds days via an argument to a macro that returns a date or timestamp
Arguments
Integer only. If no argument is passed, the filter will add 1 day
Example
Macro string:
%datetime_field|addDay(5)%
Result if datetime_field
is filled with value "2022-10-22T17:49"
1666882140000
addMonth
Adds months via an argument to a macro that returns a date or timestamp
Arguments
Integer only. If no argument is passed, the filter will add 1 month
Example
Macro string:
%datetime_field|addMonth(5)%
Result if datetime_field
is filled with value "2022-10-22T17:49"
1647964140000
addYear
Adds years via an argument to a macro that returns a date or timestamp
Arguments
Integer only. If no argument is passed, the filter will add 1 year
Example
Macro string:
%datetime_field|addYear(5)%
Result if datetime_field
is filled with value "2022-10-22T17:49"
1824216540000
subMin
Subtracts minutes via an argument to a macro that returns a date or timestamp
Arguments
Integer only. If no argument is passed, the filter will subtract 1 minute
Example
Macro string:
%datetime_field|subMin(5)%
Result if datetime_field
is filled with value "2022-10-22T17:49"
1666449840000
subHour
Subtracts hours via an argument to a macro that returns a date or timestamp
Arguments
Integer only. If no argument is passed, the filter will subtract 1 hour
Example
Macro string:
%datetime_field|subHour(5)%
Result if datetime_field
is filled with value "2022-10-22T17:49"
1666432140000
subDay
Subtracts days via an argument to a macro that returns a date or timestamp
Arguments
Integer only. If no argument is passed, the filter will subtract 1 day
Example
Macro string:
%datetime_field|subDay(5)%
Result if datetime_field
is filled with value "2022-10-22T17:49"
1666018140000
subMonth
Subtracts montha via an argument to a macro that returns a date or timestamp
Arguments
Integer only. If no argument is passed, the filter will subtract 1 month
Example
Macro string:
%datetime_field|subMonth(5)%
Result if datetime_field
is filled with value "2022-10-22T17:49"
1653230940000
subYear
Subtracts years via an argument to a macro that returns a date or timestamp
Arguments
Integer only. If no argument is passed, the filter will subtract 1 year
Example
Macro string:
%datetime_field|subYear(5)%
Result if datetime_field
is filled with value "2022-10-22T17:49"
1508683740000
setMin
Sets a minute via an argument to a macro that returns a date or timestamp
Arguments
Integer only. If no argument is passed, the filter will set 0 minute
Example
Macro string:
%datetime_field|setMin(5)%
Result if datetime_field
is filled with value "2022-10-22T17:49"
1666447500000
setHour
Sets a hour via an argument to a macro that returns a date or timestamp
Arguments
Integer only. If no argument is passed, the filter will set 0 hour
Example
Macro string:
%datetime_field|setHour(5)%
Result if datetime_field
is filled with value "2022-10-22T17:49"
1666406940000
setDay
Sets a day via an argument to a macro that returns a date or timestamp
Arguments
Integer only. If no argument is passed, the filter will set 1 day
Example
Macro string:
%datetime_field|setDay(5)%
Result if datetime_field
is filled with value "2022-10-22T17:49"
1664981340000
setMonth
Sets a month via an argument to a macro that returns a date or timestamp
Arguments
Integer only. If no argument is passed, the filter will set 1 month
Example
Macro string:
%datetime_field|setMonth(5)%
Result if datetime_field
is filled with value "2022-10-22T17:49"
1664981340000
setYear
Sets a year via an argument to a macro that returns a date or timestamp
Arguments
Integer only. If no argument is passed, the filter will return the value without changes
Example
Macro string:
%datetime_field|setYear(2017)%
Result if datetime_field
is filled with value "2022-10-22T17:49"
1508683740000
toMinuteInMs
Converts a number of minutes into milliseconds.
Example
Macro string:
%minutes|toMinuteInMs%
toHourInMs
Converts a number of hours into milliseconds.
Example
Macro string:
%hours|toHourInMs%
toWeekInMs
Converts a number of weeks into milliseconds.
Example
Macro string:
%weeks|toWeekInMs%
toMonthInMs
Converts a number of months into milliseconds.
Example
Macro string:
%months|toMonthInMs%
toYearInMs
Converts a number of years into milliseconds.
Example
Macro string:
%years|toYearInMs%