Support

Account

Home Forums Backend Issues (wp-admin) New block.json method yields "no block types exist"

Solved

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

  • We are also having the same issue…

  • 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.

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

You must be logged in to reply to this topic.