Search
Site Essentials for Statamic

Site Essentials for Statamic

se_is_set_type

The se_is_set_type modifier is a utility modifier that can be used to easily check if a Bard or replicator field contains a specific set at some arbitrary position. As an example, this modifier can be used to simplify template code to dynamically alter visual elements based on which set type appears first.

The following would apply the bg-opacity-70 class to our header if a page_builder field exists, and the first set has the type posts_with_background :

1<header class="
2 {{ if (page_builder | se_is_set_type('posts_with_background')) }}bg-opacity-70{{ /if }}
3 "
4>
5 Header code here.
6</header>

We can check if the set matches is one of multiple types by supplying an array:

1<header class="
2 {{ if (page_builder | se_is_set_type(['type_1', 'type_2'])) }}bg-opacity-70{{ /if }}
3 "
4>
5 Header code here.
6</header>

By default the se_is_set_type modifier will check the first set in the provided field. We can alter this behavior by supplying a second argument. When supplying position arguments it is important to keep in mind that the se_is_set_type uses 0-based indexes (the first item will be index 0, the second item will be index 1, and so on):

1{{# Check if the 4th item has the "type_1" set type. #}}
2<header class="
3 {{ if (page_builder | se_is_set_type('type_1', 3)) }}bg-opacity-70{{ /if }}
4 "
5>
6 Header code here.
7</header>

Some absolutely amazing
people

The following amazing people help support this site and my open source projects ♥️
If you're interesting in supporting my work and want to show up on this list, check out my GitHub Sponsors Profile.