Skip to main content

Variables for Custom Function in Custom Member Filters

You can use custom filters defined in custom function in custom member filters.
In the custom member filter editing screen, open the custom function tab and select the custom function to apply.

Image from Gyazo

Variables for Custom Member Filters

Variable NameTypeDescription
$paramsInput VariableThe JSON set in the custom member filter is passed.
$dataOutput VariableSet either $data.result (boolean) or $data.filter (string for filtering).
If both are specified, $data.result takes precedence.

$params

The JSON set in the custom member filter is passed.

Image from Gyazo

$data.result

Specify 0/1 or false/true.

ValueDescription
0, falseDo not output any members.
1, trueOutput all members.
info

If $data.filter is also specified, $data.result takes precedence.

$data.filter

Specify a string for filtering.

Example: member_id in [2,4,5]

The format is the same as the filter applied to the Member::list endpoint.
Refer to Using the filter query function for available conditions and descriptions.

Examples of custom function

By using the Smarty plugin {date} or $smarty.session.member_id in custom function, you can create filters that change the results based on dates or members using custom member filters.

Here are some examples of custom function.

Example of using $data.result

A filter that outputs all members on the 5th of every month and no one else on other days.

{assign_array var="data" values=""}
{date var='day' time='now' format='d'}
{if $day == 5}
{append var="data" index="result" value=true}
{else}
{append var="data" index="result" value=false}
{/if}

Example of using $params and $data.result

A filter that outputs all members on the day specified in the custom member filter every month and no one else.

JSON in the custom member filter editing screen

{"special_day": 5}

custom function

{assign_array var="data" values=""}
{date var='day' time='now' format='d'}
{if $day == $params.special_day}
{append var="data" index="result" value=true}
{else}
{append var="data" index="result" value=false}
{/if}

Example of using $data.filter

A filter that outputs members with the same "business type" as the logged-in member using the custom member filter, with "business type" defined as an extended item for members.

{assign_array var="data" values=""}

{assign_array var="method_params" values=""}
{assign_array var="request_params" values=""}
{append var="method_params" index="member_id" value=$smarty.session.member_id}
{api_method
var='member'
model='Member'
method='details'
version='1'
method_params=$method_params
request_params=$request_params
}
{if $member}
{append var="data" index="filter" value="business_type=`$member.details.business_type.key`"}
{else}
{append var="data" index="result" value=false}
{/if}

Support

If you have any other questions, please contact us or check out Our Slack Community.