I’m putting display conditions on a number of blocks in my page. One of these concerns displaying a block and looping through its content only if the repeater is not empty.
What I want to do:
- Display an entire block only when the repeater is not empty
- Looping through items within the block
As far as I can tell, I need to set two query loops. The first one just to check whether the repeater is not empty (and display the entire block or not), and the second one to display the repeater items if the block is displayed.
…obviously, what I end up with is a double loop, displaying the number of items x the number of items.
How best to do this? I just can’t seem to be able to do this correctly using only the ACF repeater from the dynamic data list. Also, please see the attached screenshot.
Thanks!
1 Like
Hi,
maybe you may try conditional logic on section.
{query_results_count:quer34}
. “quer34” in this example is the query loop ID, which you can retrieve by copying the element ID of the query element into your clipboard. Make sure to remove the “#brxe-” prefix. You only want to use the last six-character ID.
2 Likes
Thanks for the suggestion @clickfusion63 , but I can’t get it to work. Am I implementing this wrong? Please see screenshot.
Also tried @MartinWB 's suggestion. Doesn’t work either. See screenshot.
Thanks for your patience, guys. I should stick to goat herding.
you do not need to have two query loops. Disable query on main block. Use just one condition and one query loop.
Just checking: I now have a condition on the container block which should refer to the query block? Because that is not working.
(the bottom query block id is Clients)
There may be an error in the quotes, they should be straight.
{echo:have_rows('rep')}
Before use, you can check the operation of the tag by simply displaying it as text. If everything is good, the number 1 should appear
1 Like
Yes, this did the trick! Thank you so much @clickfusion63 and @MartinWB !!!
Also adding a screenshot of the setup for future reference. So happy this has been solved.
1 Like
It will work as well, with default ID not new one. So in case of usage you will check for default ID not your renamed one.
{query_results_count:xyzxyz}
2 Likes
Hi guys,
This worked for my set up:
{query_results_count:xyzxyz}
Great tip for hiding a section if no repeater elements have been set, but, how could I also set a condition so that if the first repeater doesn’t contain any content? At present a user can add a row/repeater, but not input any content, but also, the repeater isn’t a required section.
Thanks