Support

Account

Home Forums Gutenberg js fires before block is rendered Reply To: js fires before block is rendered

  • @yueng actually, the wp_enqueue_script, when included in the enqueue_assets part of acf_register_block should include it in the frontend and backend for your block, here’s what mine looks like:

    ...
    'enqueue_assets' 	=> function(){ 
        	//Stack the Assets in the Order we Need Them
        	wp_enqueue_style( 'slideshow-block-style', get_template_directory_uri() . '/template-parts/block/css/slideshow.css', array('general-block-style') ); //Requires all-blocks.css
    	wp_enqueue_style( 'slick-main', get_template_directory_uri() . '/template-parts/block/css/slick/slick.css' );
    	wp_enqueue_style( 'slick-theme', get_template_directory_uri() . '/template-parts/block/css/slick/slick-theme.css' );
    	wp_enqueue_script( 'slideshow-block-library', get_template_directory_uri() . '/template-parts/block/js/slick.min.js', array('jquery'), '', true ); 
    	wp_enqueue_script( 'slideshow-block-script', get_template_directory_uri() . '/template-parts/block/js/slideshow.js', array('jquery'), '', true ); 
    },
    ...

    Also, I took a second look at my slideshow javascript and the only real difference I have is an each jQuery function (which might help):

    $(document).ready(function(){
            $('.banners').each(function(){
                init_banner( $(this) );
            });
        });

    Let me know if that helps.