Home › Forums › Gutenberg › Check if Innerblocks is empty › Reply To: Check if Innerblocks is empty
I have found a solution to this if anyone is interested.
When using renderTemplate ACF renders the template and then replaces <InnerBlocks /> with the actual rendered blocks after the fact.
However, if you use renderCallback instead the second argument of the callback is the fully rendered inner blocks and therefore this would work:
function my_render_callback($block, $content, $is_preview=false) {
if($is_preview) {
echo "<InnerBlocks />"; // render JSX in the editor
}
else {
$has_inner_blocks = strnlen($content) > 0;
if($has_inner_blocks) {
echo $content;
}
}
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.