英文:
InnerBlocks templateLock="all" issue on WordPress 6.1.1
问题
我有一个自定义块,使用InnerBlocks
创建一个包含3列模板,并使用templateLock="all"
属性来防止用户移动/删除或添加模板中的内容。它在WordPress 6.0.3(及以下版本)上正常工作,但当我升级到6.1.1后出现问题。它不是锁定模板并显示我应该能够添加其他块的列,而是隐藏了新插入的列,使它们在编辑器中无法选择。
以下是我创建内部块的方式:
<window.wp.blockEditor.InnerBlocks
template={new Array(3).fill(['core/column', {}])}
templateLock="all"
/>
以下是当我复制该块时的内容:
<!-- wp:attest/grid-columns {"numColumnsStr":"3"} -->
<div class="grid grid--columns-3"><!-- wp:column -->
<div class="wp-block-column"></div>
<!-- /wp:column -->
<!-- wp:column -->
<div class="wp-block-column"></div>
<!-- /wp:column -->
<!-- wp:column -->
<div class="wp-block-column"></div>
<!-- /wp:column --></div>
<!-- /wp:attest/grid-columns -->
我尝试查看自WordPress 6.0.3以来的更改,但找不到有用的信息。
感谢您的帮助。
英文:
I have a custom block that creates a 3 column template with InnerBlocks
and a templateLock="all"
attribute to avoid that users move/remove or add something in the template. It used to properly work on WordPress 6.0.3 (and bellow) but then when I updated to 6.1.1 it had issues. Instead of locking the template and showing the columns in which I should be able to add other blocks, it hides the newly inserted columns so that they are unselectable in the editor.
Here is how I create the innerBlocks
<window.wp.blockEditor.InnerBlocks
template={new Array(3).fill(['core/column', {}])}
templateLock="all"
/>
Here is what I have when I copy the block
<!-- wp:attest/grid-columns {"numColumnsStr":"3"} -->
<div class="grid grid--columns-3"><!-- wp:column -->
<div class="wp-block-column"></div>
<!-- /wp:column -->
<!-- wp:column -->
<div class="wp-block-column"></div>
<!-- /wp:column -->
<!-- wp:column -->
<div class="wp-block-column"></div>
<!-- /wp:column --></div>
<!-- /wp:attest/grid-columns -->
I've tried to look at the changes since WordPress 6.0.3 but couldn't find something useful.
Thanks for you help.
答案1
得分: 0
事实上,子块继承了父块的 templateLock
属性,因此这些列是存在的,只是被锁定了,而且由于它们是新插入的,所以它们是空的,因此呈现为不可见。因此,想法是默认解锁 core/column
块及其(未来的)子块。以下是我的更新后的代码:
<window.wp.editor.InnerBlocks
template={new Array(numColumns).fill(['core/column', {templateLock: false, lock: {move: false, remove: false}}])}
templateLock='all'
/>
英文:
In fact child blocks inherits from parent's templateLock
attribute so the columns were present, they were just locked and as they are newly inserted, they were empty thus rendered invisible. So the idea is to unlock the core/column
block and its (future) child blocks by default. Here is my updated code
<window.wp.editor.InnerBlocks
template={new Array(numColumns).fill(['core/column', {templateLock: false, lock: {move: false, remove: false}}])}
templateLock='all'
/>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论