carbon-fields icon indicating copy to clipboard operation
carbon-fields copied to clipboard

Gutenberg Blocks with complex field

Open iamalessiopaoletti opened this issue 2 years ago • 1 comments

Hi,

I tried to build a gutenberg block with a complex field but I don't understand how to display the values, the method that I use usually in container fields doesn't work:

` Block::make( __( 'F.A.Q.' )) ->add_fields( array(

	Field::make( 'complex', 'faq', __( 'FAQ' ))
	->add_fields( array(
			Field::make( 'text', 'title', __( 'Titolo' )),
			Field::make( 'rich_text', 'txt', __( 'Testo' ) ),
			Field::make( 'image', 'image', __( 'Block Image' )),
			Field::make( 'file', 'file', __( 'File download' )),
	))
	->set_header_template('<%- title %>')
	->set_collapsed(true),


))
->set_render_callback( function ( $fields, $attributes, $inner_blocks ) { ?>


		<div class="faq">

				<?php  $fields_faq = carbon_get_the_post_meta('faq'); if($fields_faq){ foreach ( $fields_faq as $f ){ ?>

						<h2><?php echo $f['title']; ?></h2>
						
				<?php }} ?>

		</div>

<?php });

`

iamalessiopaoletti avatar May 12 '23 16:05 iamalessiopaoletti

I reproduced it. As I see in $fields_faq = null. In the callback function $fields is available as an array.

SergioChizhikov avatar May 14 '23 09:05 SergioChizhikov