Home › Forums › Backend Issues (wp-admin) › New block.json method yields "no block types exist"
Hello all,
I am trying to use the new block.json method of registering blocks and I’m clearly missing something. I used the TwentyTwentyTwo theme to test and when I follow the new ACF Blocks Documentation, and then try to set the Location Rule for the Block, I keep getting “No block types exist”…
I am on WP 6.0.2 and ACF PRO 6.0.2. My code is shown below:
twentytwentytwo/blocks/testimonial/block.json
{
"name": "acf/testimonial",
"title": "Testimonial",
"description": "A custom testimonial block",
"style": [ "file:./testimonial.css" ],
"category": "formatting",
"icon": "admin-comments",
"keywords": ["testimonial", "quote"],
"acf": {
"mode": "edit",
"renderTemplate": "testimonial.php"
},
"align": "full"
}
twentytwentytwo/functions.php includes:
add_action( 'init', 'register_acf_blocks', 5 );
function register_acf_blocks() {
register_block_type( get_template_directory_uri() . '/blocks/testimonial' );
}
I also have file twentytwentytwo/blocks/testimonial/testimonial.php but simply copy and pasted from the new docs. Still not able to find a registered block when trying to set Location Rule to Block = … Thanks in advance for anyone who is willing to help.
I have exactly the same problem. I am unable to register blocks using the ACF documentation for registering json blocks
Good afternoon mates. I contacted support and they gave me a solution that worked for me.
I share it with you. Luck
——————————————————————————
The register_block_type() expects a filesystem path(as illustrated at https://drive.google.com/file/d/1j_IaTnRnEJLFraiUKsYrdi5yEhWSkzy8/view?usp=sharing).
That said, please try using the __DIR__ . ‘/path-to-the-block-file.json ensuring the complete path to .json file is added. For example:
register_block_type( __DIR__ . ‘/blocks/testimonial/block.json’ );
In other words, you can try replacing get_template_directory_uri() with __DIR__ or get_template_directory() in block registration code.
Also, confirm if the path returned resolves to your /block.json file.
Thanks, all. I just heard back from support as well and the answer provided by JonasCn got it working for me.
In case of errors after fixing the render path – I’m using the handle-name for all scripts and styles just because the new API 2 in ACF is not fully compatible with native blocks JSON like I should expect.
Once again – the new docs – sucks! & need to be fixed asap.
hey all, I’ve checked the path that returns my json file and it’s definitely the right path but I still can’t register my block.
I triple-checked everything:
function register_acf_blocks() {
register_block_type( __DIR__ . '/blocks/custom-block/custom-block.json' );
}
add_action( 'init', 'register_acf_blocks' );
In my themefolder I’ve got a folder “/blocks/custom-block/” with my json file “custom-block.json” and a “custom-block.css” and “custom-block.php” file.
I’m working on a local install, ACF is latest (6.0.7) WP is latest (6.1.1) and I get no errors or warnings.
Anyone got other ideas why the block won’t register?
This is slowly driving me mad …
Thanks
Hi @zaphod, I’m not sure, but I think you shouldn’t change the name of the .json file. Just name it block.json and see if it works.
ARE YOU KIDDING ME????
Thank you so much – it was really just that. OMG I can’t believe that the json file really has to be called block.json!!!
Was I really the only one who didn’t get that?
Thanks again
Hi @zaphod, you are not the only one)
I was struggling an hour until I found this post.
I don’t understand why they did so.
For example, I want to have a folder called “acf-block-json” in my plugin, and have all the block json files within it. I don’t like the template rendering, so I don’t have a file/folder structure for block templates. Instead, I have all the blocks as HTML rendering functions.
Now, with this limitation, I can’t achieve that. But I think the limiation comes fro WP itself.
Hey, I came across this post whilst updating my projetcs to the new block.json registering technique.
I followed all the advice above but still my block was not showing up. I ran my block.json file through a validator which tidied it up, corrected an erroneous quote mark and then it worked!
It seems if your block.json isn’t valid or has errors, it fails silently and you never know. So double check that json and hopefully that will also help.
You must be logged in to reply to this topic.
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.