I currently use a custom function which accepts a $layout
object as parameter. This function checks to see if the layout has any, non-hidden blocks. This way it is very easy to avoid rendering a layout row with no blocks (or only hidden blocks).
function layoutHasBlocks ($layout) {
foreach ($layout->columns() as $column) {
// if has blocks
if ($column->blocks()->isNotEmpty()) {
foreach ($column->blocks() as $block) {
// if has a visible block
if (!$block->isHidden()) {
return true;
}
}
}
}
}
Ideally this would be a method of the $layout
object, so could be easily used as:
$layout->hasBlocks()
I do the same but I had no idea you can hide blocks until now. lol Thanks for posting the code