Hello all, I am currently wondering about a conditional InnerBlock based on an ACF true/false field.
I’ve got a block with two child blocks, cards picker (relationship) and cards query (taxonomy / post type). These are then rendered in a parent block (cards) where the true/false will conditionally display one of the child blocks (picker or query)
I know you can’t use two InnerBlocks in a block but for the use case of true/false this seems to work, if you switch the query_type (e.g. query, picker) you lose all populated values on switch, but within the new state it saves fine, so this would be acceptable for my use case. I could just create two blocks and probably will, but it struck me that this might be a useful pattern?
I’m trying to figure out if I should do this, it works, it saves, it renders, and it feels like it would be more useful to the editor to be able to just have one block and chose the type rather than two…..but is there any downsides to this approach in people’s opinion
$block_template_picker = array(‘core/acf/cards-picker’)
$block_template_query = array(‘core/acf/cards-query’)
if ( get_field( ‘query_type’ ) == ‘query’ ) :
<InnerBlocks template=”$block_template_picker” />
<InnerBlocks template=”$block_template_query” />