组块是一个具有自定义类的现成模式包装器mywrapper
:
<!-- wp:group {"className":"mywrapper"} -->
<div class="wp-block-group mywrapper"><div class="wp-block-group__inner-container">
...pattern...
</div></div>
<!-- /wp:group -->
理论上,可以使用自定义html块作为模式,如:
<!-- wp:html -->
<div class="mywrappper">
<h1 class="has-text-align-center">Block 1</h1>
<h2 class="has-text-align-center">Block 2</h2>
</div>
<!-- /wp:html -->
但不是最好的用户体验:-)
如果要编写自己的块来处理此问题InnerBlocks 构件支持嵌套块和version 2 它成为块api的一部分,例如:
import { __ } from \'@wordpress/i18n\';
import { registerBlockType } from \'@wordpress/blocks\';
import { InnerBlocks, useBlockProps } from \'@wordpress/block-editor\';
registerBlockType( \'wpse/wrapper\', {
apiVersion: 2,
title: __( \'WPSE Wrapper\', \'wpse\' ),
icon: \'text-page\',
category: \'design\',
edit: ( props ) => {
const blockProps = useBlockProps( { className: \'mywrapper\' } );
return <div { ...blockProps }><InnerBlocks /></div>;
},
save: ( props ) => {
const blockProps = useBlockProps.save( { className: \'mywrapper\' } );
return <div { ...blockProps }><InnerBlocks.Content /></div>;
},
} );
然后,可以使用以下内容包装块填充图案:
<!-- wp:wpse/wrapper -->
<div class="wp-block-wpse-wrapper mywrapper">
...pattern...
</div>
<!-- /wp:wpse/wrapper -->
要生成包含
.mywrapper
班