Filters and Hooks

Customize the query and output of the shortcode for a View.

Please make sure you've installed the latest version of the plugin before using these filters.

Some filters are common and available in both the Lite and Pro plugin versions, where some are only available in the Pro version, these have been labelled as (Pro).

This page lists hooks that are common for both Views and Cards. Check the child pages to see hooks related to Views and Cards.

Common hooks list

acf_views/container (Pro)

acf_views/twig/custom_functions (Pro)

acf_views/twig/custom_filters (Pro)

Common hooks description

Container (Pro)

Using this hook, you can define a PHP-DI container, and then use it inside Custom_View_Data and Custom_Card_Data classes. Read more

use DI\Container;

$container = new Container();

add_filter( 'acf_views/container', function () use ( $container ) {
	return $container;
} );

Custom Twig functions (Pro)

add_filter('acf_views/twig/custom_functions', function (array $customFunctions): array {
    return array_merge($customFunctions, [
        [
            'prefixer',
            function ($firstArg) {
                return 'prefix2' . $firstArg;
            }
        ]
    ]);
});

add_filter('acf_views/twig/custom_functions', function (array $customFunctions): array {
    return array_merge($customFunctions, [
        [
            'prefixerWithHtml',
            function ($firstArg) {
                return '<strong>prefix</strong>' . $firstArg;
            },
            ['is_safe' => ['html',],]
        ]
    ]);
});

Note: every item of the array represents the custom function. First argument is the function name, second is the callback. Third argument is optional, here you can pass any function settings supported by Twig.

For the function callback, you can define as much arguments as you need.

Now you can call your functions in twig templates of your Views and Cards.

{{ prefixer(myVar) }}
{{ prefixerWithHtml(myVar) }}

Custom Twig filters (Pro)

add_filter('acf_views/twig/custom_filters', function (array $customFunctions): array {
    return array_merge($customFunctions, [
        [
            'prefixer',
            function ($value, $firstArg) {
                return $firstArg . $value;
            }
        ]
    ]);
});

add_filter('acf_views/twig/custom_filters', function (array $customFunctions): array {
    return array_merge($customFunctions, [
        [
            'prefixerWithHtml',
            function ($value, $firstArg) {
                return '<strong>'.$firstArg.'</strong>' . $value;
            },
            ['is_safe' => ['html',],]
        ]
    ]);
});

Note: every item of the array represents the custom filter. First argument is the filter name, second is the callback. Third argument is optional, here you can pass any filter settings supported by Twig.

For the filter callback, you can define as many arguments as you need.

Now you can call your filters in twig templates of your Views and Cards.

{{ myVar|prefixer("prefix") }}
{{ myVar|prefixer("prefix") }}

Do you need to customize something but a filter isn't available?

Then Contact us and we'll try to add it as soon as possible.

Last updated