Support

Account

Home Forums Gutenberg No rendering in front end

Solved

No rendering in front end

  • Hi !

    I tried to register a block with acf as followed:

    add_action('acf/init', 'bwb_content_gallery');
    function bwb_content_gallery() {
    
       // Check function exists.
    	if( function_exists('acf_register_block_type') ) {
    
    		// register a testimonial block.
    		acf_register_block_type(array(
    			'name'              => 'bwb_gallery',
    			'title'             => __('Galerie Lexuberance'),
    			'description'       => __(''),
    			'render_callback'   => 'acf_render_callback',
    			'category'          => 'formating',
    			'icon'              => 'schedule',
    			'keywords'          => array( 'gallery', 'lexuberance' ),
    			'mode'				  => 'edit'
    		));
    	}
    }

    To have a rendering I used ‘render_template’ as first but nothing appears in front-end.
    To avoid any path issues with my template I decided to use ‘render_callback’ then.

    function acf_render_callback( $block, $content = "", $is_preview = false, $post_id = 0 ) {
    	?>
    	<p>RENDERING</p>
    	<?php
    }
    

    “RENDERING” is showing in the editor but nothing in front-end.

    Am I missing something ? How to render my block in front-end ?

  • Hello,

    Were you able to resolve this? I have the same issue and I have searched everywhere for a solution but so far no luck.

    Thanks

  • Why are there no answers to this question!?!??! It’s been asked quite a bit across various sites.

    My issue is essentially the same apart from the JSON for the ACF block is being loaded in the DOM but the block isn’t being rendered. Surely someone has an answer since it’s not a one-off issue that people are experiencing??

  • Alright, I completely forgot about that.
    I hope it’ll help you but to resolve my problem it looks like I just changed the way to call my template.

    add_action('acf/init', 'bwb_content_gallery');
    function bwb_content_gallery() {
    
       // Check function exists.
    	if( function_exists('acf_register_block_type') ) {
    
    		// register a testimonial block.
    		acf_register_block_type(array(
    			'name'              => 'bwb_gallery',
    			'title'             => __('Galerie Lexuberance'),
    			'description'       => __(''),
    			'render_template'   => './templates/blocks/gallery.php',
    			'category'          => 'formating',
    			'icon'              => 'schedule',
    			'keywords'          => array( 'gallery', 'lexuberance' ),
    			'mode'				  => 'edit',
    			'enqueue_style'     => get_template_directory_uri() . '/dist/css/blocks.css',
    		));
    	}
    }

    As you can see in “render_template” I directly put the path to the template I want to see and it does work.

  • Thanks for the response, and for finding your code from 1 year and a half ago – much appreciated! Unfortunately I’ve not had any luck with render_template option either. All renders fine within the editor, but nothing on the front end. I’ll keep digging though. Thanks! 🙂

  • Mine was resolved just like @paulg stated. But perhaps you can try this plugin https://hookturn.io/downloads/acf-theme-code-pro/ if you’re not already aware. It automatically generates a php code immediately after you create AFC fields. The tutorial has very clear instructions

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.