How can I use MB-Blocks as template registered post type?

Support MB Blocks How can I use MB-Blocks as template registered post type?Resolved

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #16510
    closemarketingclosemarketing
    Participant

    Hello,
    I'd like to force to use the block in a registered post type. I can use template argument in register_post_type, but it seems that is not working.

    Is it possible?

    #16529
    Anh TranAnh Tran
    Keymaster

    Hello,

    I'm not sure what you meant. If a post has block editor enabled, then all the registered blocks are available. Or did you mean to set the default content for a post of a specific post type? I found a post on this topic, but not sure if that works for Gutenberg.

    #16539
    closemarketingclosemarketing
    Participant

    Hello in register_post_type, you can have block templates. It should be nice to have as default the block in a post type:

    'template' => array( 'layout/name-block' ),
    'template_lock' => 'all',

    But I'm not sure which values use in template.

    Regards.

    #16579
    Anh TranAnh Tran
    Keymaster

    I got it.

    The custom blocks registered with MB Blocks have id meta-box/{$block_id}. So you can define your post type template like:

    'template' => ['meta-box/hero', 'meta-box/team-member']
    
    #16597
    closemarketingclosemarketing
    Participant

    Very nice!!!

    Thanks!

    #16598
    closemarketingclosemarketing
    Participant

    I get a blank page when i use the template...

    #23655
    Jacob HillJacob Hill
    Participant

    I'm wondering the same thing! I'd like to create a CPT, register a block, and then REQUIRE that block on new CPT items, but prevent other blocks from being added.

    When I add the template line, I also get a blank page.

    Reference: https://wordpress.org/support/topic/is-it-possible-to-create-a-standardized-and-fixed-blocks-cpt/#post-12773298

    #23656
    Jacob HillJacob Hill
    Participant

    I figured this out! I had to use different syntax:

    'template' => array(
        array( 'meta-box/{$block_id}' ),
    ),
    'template_lock' => 'all',
    #23659
    Jacob HillJacob Hill
    Participant

    Can this be added to the blocks extension's documentation? https://docs.metabox.io/extensions/mb-blocks/

    #23668
    closemarketingclosemarketing
    Participant

    Thanks for sharing!

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.