admin管理员组文章数量:1277580
Whenever I attempt to define a level other than H2 for 'core/heading' in any block template, upon reload of the page editor, the block gets a "This block contains unexpected or invalid content" error, and when the "Attempt Block Recovery" button is clicked, the block level is changed to level 2. Why would I not seem to be able to use any other level than 2 in a block template?
Example template excerpt:
<?php
$template = [
[
'core/heading',
[
'level' => '2',
'content' => 'Directions',
'className' => 'block-header-directions',
],
],
[
'core/heading',
[
'level' => '3',
'placeholder' => 'Subheading',
'className' => 'block-subheader-directions has-blue-alt-color',
],
],
[
'core/list',
[
'placeholder' => 'List item',
'ordered' => true,
'className' => 'block-list-directions',
],
],
];
In the above example, the block with the placeholder "Subheading" causes that chain of events.
I thought initially that this was potentially some enforcement of semantics (that Gutenberg wanted to see H1, H2, H3, etc. in the correct order in the content), but it occurs, as in the case above, even when the heading levels are in a completely sematic order in the content.
(Potentially related, as the forced H2 problem seems to extend to other editor areas as well: I've added a block style to 'core/heading', so the block editor now displays previews of the styles. But no matter which heading level is selected, only the preview for the H2 heading is displayed.)
Whenever I attempt to define a level other than H2 for 'core/heading' in any block template, upon reload of the page editor, the block gets a "This block contains unexpected or invalid content" error, and when the "Attempt Block Recovery" button is clicked, the block level is changed to level 2. Why would I not seem to be able to use any other level than 2 in a block template?
Example template excerpt:
<?php
$template = [
[
'core/heading',
[
'level' => '2',
'content' => 'Directions',
'className' => 'block-header-directions',
],
],
[
'core/heading',
[
'level' => '3',
'placeholder' => 'Subheading',
'className' => 'block-subheader-directions has-blue-alt-color',
],
],
[
'core/list',
[
'placeholder' => 'List item',
'ordered' => true,
'className' => 'block-list-directions',
],
],
];
In the above example, the block with the placeholder "Subheading" causes that chain of events.
I thought initially that this was potentially some enforcement of semantics (that Gutenberg wanted to see H1, H2, H3, etc. in the correct order in the content), but it occurs, as in the case above, even when the heading levels are in a completely sematic order in the content.
(Potentially related, as the forced H2 problem seems to extend to other editor areas as well: I've added a block style to 'core/heading', so the block editor now displays previews of the styles. But no matter which heading level is selected, only the preview for the H2 heading is displayed.)
Share Improve this question asked Oct 31, 2021 at 1:00 StudioAlStudioAl 4941 gold badge3 silver badges15 bronze badges1 Answer
Reset to default 4A new day, and refreshed Google-fu powers provided the simple answer:
The level
attribute needs to be an integer, not a a string.
[
'core/heading',
[
'level' => 3,
'placeholder' => 'Subheading',
'className' => 'block-subheader-directions has-blue-alt-color',
],
]
本文标签: Creating Block templates with 39coreheading39 other than level 2
版权声明:本文标题:Creating Block templates with 'coreheading' other than level 2 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741242105a2364181.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论