This seems like it should be easy
I agree, it should be straight-forward to check the value of an ACF checkbox field. If it wasn’t clear from the documentation, or if the template language doesn’t support a simple method, we can improve it.
Looping over the checkbox values, and checking with <If field>
works:
<Loop acf_checkbox=online_ordering_options>
<If field is value="delivery">DELIVERY</If>
</Loop>
Passing a field value to check
:
<If check="{Field acf_checkbox=online_ordering_options}" any_is value=delivery>
Surprisingly, this works. The result of Field
is a JSON array, but the comparison any_is
knows how to handle it.
Then I tried a shortcut with includes
.
<If acf_checkbox=online_ordering_options includes value=delivery>
I like this syntax the best, but that didn’t work as expected. Looking in the code, I found that the checkbox field is passed as a List loop with its values, and the comparison includes
doesn’t handle that currently. OK, I’ve made a note to improve this in the next version of L&L to support the above syntax.
(Now that I’m thinking, any_is
and includes
mean pretty much the same thing: “if any item in the list is a value”, and “if the list includes a value”. They should probably be consolidated to use the same logic. EDIT: Nope, on closer view, they’re slightly different. includes
will match a value in a piece of text as-is, but any_is
will convert the text into a list as comma-separated values. Also, any_is_not
and not_includes
behave differently too. I wish these could be made more consistent and simpler somehow.)