Home › Forums › General Issues › Creating ACF blocks with a plugin does not find the render_template › Reply To: Creating ACF blocks with a plugin does not find the render_template
Not sure if this is helpful, but here’s a setup I’ve been using:
*acf-blocks-plugin.php
**blocs/blockname/blockname.php
**blocs/blockname/blockname_template.php
**blocs/blockname/blockname_style.css
In *acf-blocks-plugin.php I’m calling
// Get plugin Path directory
if ( !defined( 'FP_PLUGIN_PATH' ) ) {
define( 'FP_PLUGIN_PATH', plugin_dir_path( __FILE__ ) );
}
if ( !defined( 'FP_PLUGIN_URI' ) ) {
define( 'FP_PLUGIN_URI', plugin_dir_url( __FILE__ ) );
}
and then
add_action('acf/init', 'fp_acf_init');
function fp_acf_init() {
// check function exists
if( function_exists('acf_register_block_type') ) {
// register the Product Select block
include( FP_PLUGIN_PATH . 'blocks/prodselect/prodselect-block.php');
// register the Product Image Select block --> Images with lightbox
include( FP_PLUGIN_PATH . 'blocks/prodimage/prodimage-block.php');
Inside a **blocs/blockname/blockname.php there’s the usual ACF block code
// register the products filter block
acf_register_block_type(array(
'name' => 'fp_blocklink',
(…)
'post_types' => array( 'post', 'page', 'fp_produkt' ),
'render_template' => FP_PLUGIN_PATH . '/blocks/blocklink/blocklink-template.php',
'enqueue_style' => FP_PLUGIN_URI . 'blocks/blocklink/blocklink-style.css',
));
I’m not really sure the enqueue_style makes much sense, TBH, but the rest seems to be working OK so far.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.