Home Forums General Issues Creating ACF blocks with a plugin does not find the render_template


Creating ACF blocks with a plugin does not find the render_template

  • Hi there everyone.

    I have been using ACF for a very long time now, and now I wanted to create a plugin for myself that uses all the blocks I normaly create from scratch all the time.

    I have been creating blocks in the theme, and that is working excelent.
    But now that I’m creating a plugin, I’m having some issues on the “render_template” part.

    In my plugin root folder, I have the root php file for my core stuff.
    In this Php file I “require” my acf-blocks php file where I create all my blocks.

    @require "blocks/gw-blocks.php";

    In my acf-blocks.php file I use this code:

    function register_acf_block_types() {
    	// Register content block
    		'name'				=> 'testimonial',
    		'title'				=> __('Clean Testimonial'),
    		'description'		=> __('A testimonial displaying an image and person information'),
    		'render_template'	=> 'block/testimonial.php',
    		'category'			=> 'formatting',
    		'icon'				=> 'media-text',
    		'keywords'			=> array( 'text', 'content', 'image', 'testimonial' ),
    if( function_exists( 'acf_register_block_type' ) ) {
    	add_action( 'acf/init', 'register_acf_block_types' );

    render_template here is looking for the folder blocks and the file testimonial.php inside that. My testimonial.php is in the same folder as acf-blocks.php that creates the blocks.

    But when I require from the root php file, then I have to assume that the blocks are created on root, and therefor has to target the folder first and then the blocks.

    This is my folder setup:

    **** testimonial.php
    **** acf-blocks.php

    ** = Folder
    **** = files inside folder
    * root files

    I have tried to use these as render template:

    "plugin_dir_path( __FILE__ ) . "block/testimonial.php"
    "plugin_dir_path( __FILE__ ) . "/block/testimonial.php"

    None of these are working.
    I can select the block on the page without any problem, but there is just not anything showing. Not even my placeholder test on the fields.

    This is my testimonial.php file:

     * Testimonial block
    $id = 'gweb-testimonial-' . $block['id'];
    if( !empty($block['anchor']) ) {
    	$id = $block['anchor'];
    // Create class attribute allowing for custom "ClassName" and "align" values.
    $className = 'gweb-testimonial';
    if( !empty($block['className']) ) {
    	$className .= ' ' . $block['className'];
    if( !empty($block['align']) ) {
    	$className .= ' align' . $block['align'];
    // Load values and assign defaults
    $name			= get_field('name') ?: "Name of the person...";
    $title			= get_field('title') ?: "Title of the person...";
    $email			= get_field('email') ?: "Person's Email";
    $areaCode		= get_field('area_code') ?: "00";
    $phoneNumber	= get_field('phone_number') ?: "999 9999 999";
    $person			= get_field('person');
    $background		= get_field('background_color');
    $leftRight		= get_field('left_or_right');
    <div class="<?php echo esc_attr($className); ?>" id="<?php echo esc_attr($id); ?>" style="background-color: #<?php echo $background; ?>">
    	<?php if($leftRight === 'left') : ?>
    		<img src="<?php echo $person; ?>" alt="">
    	<?php endif; ?>
    		<div class="person">
    			<h2><?php echo $name; ?></h2>
    			<h4><?php echo $title; ?></h4>
    			<div class="contact_info">
    				<a href="mailto: <?php echo $email; ?>"><?php echo $email; ?></a>
    				<a href="tel: +<?php echo $areaCode; ?> <?php echo $phoneNumber; ?>">+<?php echo $areaCode . " " . $phoneNumber; ?></a>
    	<?php if($leftRight === 'right') : ?>
    		<img src="<?php echo $person; ?>" alt="">
    	<?php endif; ?>

    So I would realy appreciate any help I can get on this matter so that I can start using my plugin to get the work load a little lighter in the future.

    And yes, I have ACF Pro

    Best Regars
    – JP

  • Nobody? I still have not found the answer anywhere to what may cause this.
    I have checked the path, and the path is correct.

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

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.