For the complete documentation index, see llms.txt. This page is also available as Markdown.

Smart Twig templates

In Advanced Views, Layout and Post Selection templates support Twig as a template engine.

If you're new to Twig, read our Twig features review.

1. Functions by Advanced Views

We extended Twig to include additional WordPress-related functions, in addition to its built-in functions. You can find these extended functions listed below.

{{ print_r(my_array) }}
{# calls the built-in PHP print_r function (displays the array for debug purposes) #}

{{ wp_interactivity_state('name', {stateArg:'some'}) }}
{# calls the built-in WordPress wp_interactivity_state function #}

{{ wp_interactivity_data_wp_context({contextArg:'some'}) }}
{# calls the built-in WordPress wp_interactivity_data_wp_context function #}

{{ paginate_links({total:'10',}) }}
{# calls the built-in WordPress paginate_links function #}

You'll use the interactivity functions in Layouts when employing the WP Interactivity API, while paginate_links is used inside Post Selections when the 'Source: Page content' option is chosen.

{{ _query_argument('my-category-id') }} 
{# retrieves the argument from the current page URL ($_GET in PHP) #}

{{ _is_user_with_role("role") }} 
{# checks if user has the specified role. 
You can pass user id as the second argument, or it'll use the current user id #}

{{ _is_user_logged_in() }} 
{# calls is_user_logged_in() from WP #}

{{ _site_url("/my-page") }} 
{# calls site_url() from WP #}

{{ _home_url() }} 
{# calls home_url() from WP #}

{{ __("Some label") }} 
{# translates the label. 
You can pass the text domain as the second argument, 
or it'll use the "Text Domain" of your theme 
(declared in the headings of the style.css file of your theme) #}

2. Filters by Advanced Views

3. Customization

You can also add your own Twig functions and filters. Check this hooks guide to learn more.

3. Twig version

Currently, Advanced Views uses version 3.7.1 of the Twig engine.

Last updated