Bricks 1.5.7 introduced a new :value
dynamic data filter.
This tutorial provides a practical example of how this filter can be used.
Meta Box Checkbox List
When a Meta Box Checkbox List type of field has both values and labels for the choices like this:
and let’s say a specific Page has the field populated like this:
To display the selected values as a comma-separated list, you could add a Basic Text component in Bricks and replace the default placeholder text with:
{mb_page_checkbox_list_inf0r0gxcl}
where checkbox_list_inf0r0gxcl
is the field ID.
But this will output the labels, not the values:
Red, Green
This is where the :value
filter comes in.
Tacking on :value
at the end of the dynamic data tag like this:
{mb_page_checkbox_list_inf0r0gxcl:value}
will output the values instead (if that is what you are trying to show):
red, green
Now let’s say you want to output a Section only if red is one of the ticked choices value.
This can be done like this:
where the dynamic data tag is the same as before, with the :value
filter:
{mb_page_checkbox_list_inf0r0gxcl:value}
ACF Checkbox
The :value
filter is not needed with ACF since the Return value for a Checkbox type of field is set to “Value” by default.
{acf_color}
outputs comma-separated values:
red, green
Note: When Return Value is set to Label, using :value
filter will NOT output the values. There does not seem to be a way to show the values without writing code in this case.
6 comments
Charles
Found this page and have the same question as Michael above. Would love to find a way to output the items as a items. Or, really, even just replace the comma with another character such as a forward slash.
Sridhar Katakam
Are you using ACF or Meta Box?
Do you prefer the output to be a list or the items to be separated by /? And, is this labels or values or both?
Charles
Thanks for the reply. Using ACF.
This all started because I wanted to separate the content by a / instead of a comma. But if it makes sense to output the labels as a list and then simply use CSS to add the / (or any character, I suppose) then that might be a good idea.
In my case labels and values are the same, but building for labels is probably the best way to go here.
Sridhar Katakam
https://www.advancedcustomfields.com/resources/checkbox/ has code for this. Is that what you are looking for?
https://d.pr/i/DgM9Tg
Michael Kern
Is there a way to get Bricks to display these in a CSS-styled list instead of just comma-separated values?
Sridhar Katakam
Not natively as far as I know. We could define a custom function for this. Which custom fields plugin do you use?