Custom Fields
Re-Envisioned
Support MB Blocks How can I use MB-Blocks as template registered post type?

  • Creator
    Topic
  • #16510
    Resolved closemarketing
    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?

Viewing 9 replies - 1 through 9 (of 9 total)
  • Author
    Replies
  • #16529
    Anh 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
    closemarketing
    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 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
    closemarketing
    Participant

    Very nice!!!

    Thanks!

    #16598
    closemarketing
    Participant

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

    #23655
    Jacob 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 Hill
    Participant

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

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

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

    #23668
    closemarketing
    Participant

    Thanks for sharing!

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