htmlburger / carbon-fields

WordPress Custom Fields Library ✨
https://carbonfields.net/
Other
1.36k stars 245 forks source link

Gutenberg Blocks with complex field #1168

Open iamalessiopaoletti opened 1 year ago

iamalessiopaoletti commented 1 year ago

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 });

`

SergioChizhikov commented 1 year ago

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