Using Gutenberg parse_blocks Function With ACF Custom Blocks?

I am trying to separate Custom ACF Gutenberg Blocks from the rest of the core blocks on a post. Currently I am using the

I am trying to separate Custom ACF Gutenberg Blocks from the rest of the core blocks on a post. Currently I am using the_content(); This is grabbing every block in the Gutenberg Editor. What I want to do now is look at all the blocks in the Gutenberg editor, check to see if they are a custom ACF block, and if they are an ACF block then output them else, don't output the block. What I have currently is:

$blocks = parse_blocks( get_the_content() );
foreach ( $blocks as $block ) {
    if ( 'acf/qd-center-copy' === $block['blockName'] ) {
      echo $block['innerHTML'];
    }
}

So what hte above function is doing is looping through the blocks in the Gutenberg editor, checking to see if the blockname is 'acf/qd-center-copy' if the block name equals 'acf/qd-center-copy' then output that block. The issue I am running into is the outputting of that block and I'm not sure what I need to do to output the custom ACF block properly.

Here is the what is ouputted for the block with the block name of 'acf/qd-center-copy' when I use print_r($block):

 Array
(
    [blockName] => acf/qd-center-copy
    [attrs] => Array
        (
            [id] => block_5caf50e1cda63
            [data] => Array
                (
                    [qd_background_color_toggle] => 1
                    [_qd_background_color_toggle] => field_5c700fe8bb525
                    [qd_headline] => Test Centered Text block
                    [_qd_headline] => field_5c70100ebb526
                    [qd_content] => Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
                    [_qd_content] => field_5c70101dbb527
                    [qd_additional_column_toggle] => 0
                    [_qd_additional_column_toggle] => field_5c701034bb528
                )

            [name] => acf/qd-center-copy
            [align] => 
            [mode] => auto
        )

    [innerBlocks] => Array
        (
        )

    [innerHTML] => 
    [innerContent] => Array
        (
        )

)

I am trying to separate Custom ACF Gutenberg Blocks from the rest of the core blocks on a post. Currently I am using the_content(); This is grabbing every block in the Gutenberg Editor. What I want to do now is look at all the blocks in the Gutenberg editor, check to see if they are a custom ACF block, and if they are an ACF block then output them else, don't output the block. What I have currently is:

$blocks = parse_blocks( get_the_content() );
foreach ( $blocks as $block ) {
    if ( 'acf/qd-center-copy' === $block['blockName'] ) {
      echo $block['innerHTML'];
    }
}

So what hte above function is doing is looping through the blocks in the Gutenberg editor, checking to see if the blockname is 'acf/qd-center-copy' if the block name equals 'acf/qd-center-copy' then output that block. The issue I am running into is the outputting of that block and I'm not sure what I need to do to output the custom ACF block properly.

Here is the what is ouputted for the block with the block name of 'acf/qd-center-copy' when I use print_r($block):

 Array
(
    [blockName] => acf/qd-center-copy
    [attrs] => Array
        (
            [id] => block_5caf50e1cda63
            [data] => Array
                (
                    [qd_background_color_toggle] => 1
                    [_qd_background_color_toggle] => field_5c700fe8bb525
                    [qd_headline] => Test Centered Text block
                    [_qd_headline] => field_5c70100ebb526
                    [qd_content] => Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
                    [_qd_content] => field_5c70101dbb527
                    [qd_additional_column_toggle] => 0
                    [_qd_additional_column_toggle] => field_5c701034bb528
                )

            [name] => acf/qd-center-copy
            [align] => 
            [mode] => auto
        )

    [innerBlocks] => Array
        (
        )

    [innerHTML] => 
    [innerContent] => Array
        (
        )

)
Share Improve this question asked Apr 11, 2019 at 15:13 user9664977user9664977 3875 silver badges12 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Try using the code below to display the html for your block. I found the solution here.

render_block( $block )

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745585821a4634533.html

相关推荐

  • Using Gutenberg parse_blocks Function With ACF Custom Blocks?

    I am trying to separate Custom ACF Gutenberg Blocks from the rest of the core blocks on a post. Currently I am using the

    18小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信