I am able to insert blocks below my Block Template on the Admin page #45500
Replies: 6 comments
-
@walter74ucla Would you be able to provide more info on how you created the block template, and the markup of the block template? Thanks. |
Beta Was this translation helpful? Give feedback.
-
Yes. Here is the php code: function register_post_type_post_template() {
// ... Define $block_template using an array of blocks. @see how to lock a block above
$block_template = [
[ 'mng/print-edit-view-buttons', [] ],
[ 'mng/mng-post-title', [] ],
[ 'core/group', [], [
[ 'mng/subhead', [] ],
[ 'core/paragraph', [] ],
] ],
[ 'mng/warning-block-template', [//This is the "last" unconditional block of the Block Template...This can be removed once we remove the block-list-appender
'lock' => [
'move' => true,
'remove' => true,
] ]
],
//The blocks below are displayed conditionally in this Block Template.
//The blocks are placed below the unconditional blocks to create the different views.
[ 'mng/edit-view', [] ],
//You can also build a Block Template using JavaScript
//https://wholesomecode.ltd/using-a-template-with-innerblocks-in-the-wordpress-block-editor-gutenberg
];
$post_type_object = get_post_type_object( 'post' );
$post_type_object->template = $block_template;
}
add_action( 'init', 'register_post_type_post_template' ); As a work around, I can display: none the block-list-appender class. |
Beta Was this translation helpful? Give feedback.
-
@walter74ucla By default templates aren't locked and are editable, including being able to insert blocks before, within or after the template. You can define |
Beta Was this translation helpful? Give feedback.
-
@talldan Is there a Block Editor component? There is a Rich Text component: https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/rich-text/README.md, but it does not have all of the behavior of the Block Editor like inserting blocks. Are there additional working examples that dive deeper into the Block Editor? |
Beta Was this translation helpful? Give feedback.
-
What is it that you're trying to achieve? Are you looking to implement your own editor? edit: I'm going to convert this to a github discussion, as issues are for bug/enhancement reports. |
Beta Was this translation helpful? Give feedback.
-
@talldan Thanks for converting this to a discussion. Ultimately, I am trying to create a Block Editor Component that can be used inside custom blocks on the post-new.php and post.php admin pages. In the Classic Editor, we can create Classic Editor meta box via Tiny MCE. I have attached a picture of the Classic Editor example. The reason we do this is to give our editors three views---Web View, Edit View, and Print View via javascript. We copy data back and forth between the views. |
Beta Was this translation helpful? Give feedback.
-
Description
I created a Block Template. However, I am still able to insert blocks on the admin page below the Block Template. To me, you use a Block Template to make sure all of the Article Activity happens within the Block Template.
Step-by-step reproduction instructions
Create a Block Template.
Then try to insert blocks below the Block Template on the New Article Admin Screen.
New blocks are place below the Block Template instead of within the Block Template.
Step 1 - New Article: add a Title, Subhead, and Paragraph
Step 2 - Add an image below the paragraph
Step 3 - Add another paragraph below the image...This paragraph is inserted below the Block Template (to me, this is a bug)
Screenshots, screen recording, code snippet
No response
Environment info
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes
Beta Was this translation helpful? Give feedback.
All reactions