Support

Account

Home Forums Gutenberg duplicate gutenberg blocks.

Unread

duplicate gutenberg blocks.

  • Hello, I have followed the instruction to create a custom gutenberg block. And it works for me! https://www.advancedcustomfields.com/resources/blocks/

    But for some reason mine blocks are getting duplicated. The duplicated version has no content only the structure duplicates. Some on has a answer for it?

    I am using blade10 + acf pro

    {{--
      Title: SellingPoint1
      Description: Selling Points
      Category: formatting
      Icon: table-row-after
      Keywords: sellingpoint quote
      Mode: edit
      Align: full
      PostTypes: page post
      SupportsAlign: left right
      SupportsMode: false
      SupportsMultiple: false
      EnqueueStyle: styles/app.scss
      EnqueueScript: scripts/app.js
      EnqueueAssets: path/to/asset
    --}}
    
    @php
      // Create id attribute allowing for custom "anchor" value.
      $id = 'sellingpoint-' . $block['id'];
      if( !empty($block['anchor']) ) {
          $id = $block['anchor'];
      }
    
      // Create class attribute allowing for custom "className" and "align" values.
      $className = 'sellingpoint';
      if( !empty($block['className']) ) {
          $className .= ' ' . $block['className'];
      }
      if( !empty($block['align']) ) {
          $className .= ' align' . $block['align'];
      }
    
      $sellingpoint_1 = get_field('sellingpoint_1');
      $sellingpoint_2 = get_field('sellingpoint_2');
      $sellingpoint_3 = get_field('sellingpoint_3');
      $subtext_1 = get_field('subtext_1');
      $subtext_2 = get_field('subtext_2');
      $subtext_3 = get_field('subtext_3');
    @endphp
    
    @if($sellingpoint_1 && $sellingpoint_2 && $sellingpoint_3)
    <section id="{{$id}}" class="{{$className}}">
      <div class="container">
        <div class="row">
          <div class="sellingpoint__one col-md">
            <div class="sellingpoint__title">
              <h3>{!! $sellingpoint_1 !!}</h3>
            </div>
            <div class="sellingpoint__subtext">
              <p>{!! $subtext_1 !!}</p>
            </div>
          </div>
          <div class="sellingpoint__one col-md">
            <div class="sellingpoint__title">
              <h3>{!! $sellingpoint_2 !!}</h3>
            </div>
            <div class="sellingpoint__subtext">
              <p>{!! $subtext_2 !!}</p>
            </div>
          </div>
          <div class="sellingpoint__one col-md">
            <div class="sellingpoint__title">
              <h3>{!! $sellingpoint_3 !!}</h3>
            </div>
            <div class="sellingpoint__subtext">
              <p>{!! $subtext_2 !!}</p>
            </div>
          </div>
        </div>
      </div>
    </section>
    add_action('acf/init', 'my_acf_init');
    function my_acf_init() {
    
    	// check function exists
    	if( function_exists('acf_register_block') ) {
    
        acf_register_block(array(
    			'name'				=> 'sellingpoint',
    			'title'				=> __('Sellingpoint'),
    			'description'		=> __('A custom sellingpoint block.'),
    			'render_callback'	=> 'my_acf_block_render_callback',
    			'category'			=> 'formatting',
    			'icon'				=> 'table-row-after',
    			'keywords'			=> array( 'Sellingpoint', 'selling', 'point' ),
    		));
    	}
    }
    
    function my_acf_block_render_callback( $block ) {
    
    	// convert name ("acf/testimonial") into path friendly slug ("testimonial")
    	$slug = str_replace('acf/', '', $block['name']);
    
    	// include a template part from within the "template-parts/block" folder
    	if( file_exists( get_theme_file_path("/blocks/content-{$slug}.php") ) ) {
    		include( get_theme_file_path("/blocks/content-{$slug}.php") );
    	}
    }
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.