Filter or ‘where clause’ is used to extract only those records that fulfill a specified condition.
Filter is the list of conditions separated by ‘and’ or ‘or’ (not both because brackets are not allowed yet).
Each condition separated by the conditional operator such as ‘=’ (or ‘<‘ or ‘<=’ or ‘>’ or ‘>=’ or ‘!=’ and ‘==’ which is exact match)
On the left side is the name of the field and on the right side is the value
Example:
price>0
Where ‘price’ is the name of the field
‘>’ conditional operator which means more than.
‘0’ is the value.
Twig tags can be used instead of the value as well. #
Example:
authoruser={{ user.id }}
This will produce the list of records where ‘authoruser’ id field is equal to current user id. To show all records that belong to a current user.
More than one condition can be used:
authoruser={{ user.id }} and active=1
Where ‘active’ is the Checkbox type field.
To get a value from the URL query parameter use {{ url.getint(‘param_name’) }} tag or equivalent.
Example:
color={{ url.getstring('string') }}
this will read the value ‘color’ from the URL query.
To get the current date use {{ ‘now’|date(‘m/d/Y’) }} or {{ ‘now’|date(‘Y’) }} for the year or {{ ‘now’|date(‘m’) }} for the month.
Also, you can format the date using MySQL date_format() format specifiers
Example:
creation={now:%m}
Example:
birthdate:%m=1
to get the month of the field value.
Filters used in Menu Item/Filter Tab/Search Parameter and in following tags: {{ record.joincount() }} {{ record.joinavg() }} {{ record.joinmax() }} {{ record.joinvalue() }} {{ record.jointable() }} {{ tables.getvalue() }} {{ tables.getrecord() }} {{ tables.getrecords() }}
and in plugins {customtablesrecord=…} and {customtablescatalog=…}
Another example, concatenating parameters using “~” operator:
{{ record.sum(“invoice”,”sum”,’counter=’ ~ record.id ~ ‘ and Invoice_date>”2024-01-01″ and Invoice_date<“2024-03-01″‘ ) }}
Leave a Reply
You must be logged in to post a comment.