admin管理员组文章数量:1022612
I am trying & learning to build custom block for Gutenberg but spent a few hours on searching for full list of "available options". Maybe I was overlook...
Refer: Template and Block
For example, placeholder
& align
are options but what else?
function myplugin_register_book_post_type() {
$args = array(
'public' => true,
'label' => 'Books',
'show_in_rest' => true,
'template' => array(
array( 'core/image', array(
'align' => 'left',
) ),
array( 'core/heading', array(
'placeholder' => 'Add Author...',
) ),
array( 'core/paragraph', array(
'placeholder' => 'Add Description...',
) ),
),
);
register_post_type( 'book', $args );
}
add_action( 'init', 'myplugin_register_book_post_type' );
Example 2:
those empty array()
should be allow to store some options, right?
$template = array(
array( 'core/paragraph', array(
'placeholder' => 'Add a root-level paragraph',
)),
array( 'core/columns', array(), array(
array( 'core/column', array(), array(
array( 'core/image', array() ),
)),
array( 'core/column', array(), array(
array( 'core/paragraph', array(
'placeholder' => 'Add a inner paragraph'
)),
)),
))
);
I am trying & learning to build custom block for Gutenberg but spent a few hours on searching for full list of "available options". Maybe I was overlook...
Refer: Template and Block
For example, placeholder
& align
are options but what else?
function myplugin_register_book_post_type() {
$args = array(
'public' => true,
'label' => 'Books',
'show_in_rest' => true,
'template' => array(
array( 'core/image', array(
'align' => 'left',
) ),
array( 'core/heading', array(
'placeholder' => 'Add Author...',
) ),
array( 'core/paragraph', array(
'placeholder' => 'Add Description...',
) ),
),
);
register_post_type( 'book', $args );
}
add_action( 'init', 'myplugin_register_book_post_type' );
Example 2:
those empty array()
should be allow to store some options, right?
$template = array(
array( 'core/paragraph', array(
'placeholder' => 'Add a root-level paragraph',
)),
array( 'core/columns', array(), array(
array( 'core/column', array(), array(
array( 'core/image', array() ),
)),
array( 'core/column', array(), array(
array( 'core/paragraph', array(
'placeholder' => 'Add a inner paragraph'
)),
)),
))
);
Share
Improve this question
edited Apr 24, 2019 at 3:43
kevinckc
asked Apr 24, 2019 at 3:38
kevinckckevinckc
731 silver badge7 bronze badges
1 Answer
Reset to default 8Option 1
Browse the block-library
package in the Gutenberg's GitHub repository, and find the block metadata in a JSON file named block.json
of the specific block. For example, for the core/image
block, you can find the metadata (e.g. all available/supported attributes) here:
https://github/WordPress/gutenberg/blob/master/packages/block-library/src/image/block.json
So basically, the URL format is:
https://github/WordPress/gutenberg/blob/master/packages/block-library/src/{name}/block.json
where {name}
is the block name without the core/
part.
Option 2 (PHP)
For blocks registered using the PHP/WordPress function register_block_type
, you can use this to get the block attributes:
$block = WP_Block_Type_Registry::get_instance()->get_registered( 'core/latest-posts' );
$attrs = $block ? $block->get_attributes() : [];
var_dump( $attrs, $block );
Option 3 (JavaScript)
For blocks registered using the JavaScript function wp.blocks.registerBlockType
, you can use this to get the block attributes:
var block = wp.blocks.getBlockType('core/gallery');
var attrs = block ? block.attributes : {};
console.log( attrs, block );
I am trying & learning to build custom block for Gutenberg but spent a few hours on searching for full list of "available options". Maybe I was overlook...
Refer: Template and Block
For example, placeholder
& align
are options but what else?
function myplugin_register_book_post_type() {
$args = array(
'public' => true,
'label' => 'Books',
'show_in_rest' => true,
'template' => array(
array( 'core/image', array(
'align' => 'left',
) ),
array( 'core/heading', array(
'placeholder' => 'Add Author...',
) ),
array( 'core/paragraph', array(
'placeholder' => 'Add Description...',
) ),
),
);
register_post_type( 'book', $args );
}
add_action( 'init', 'myplugin_register_book_post_type' );
Example 2:
those empty array()
should be allow to store some options, right?
$template = array(
array( 'core/paragraph', array(
'placeholder' => 'Add a root-level paragraph',
)),
array( 'core/columns', array(), array(
array( 'core/column', array(), array(
array( 'core/image', array() ),
)),
array( 'core/column', array(), array(
array( 'core/paragraph', array(
'placeholder' => 'Add a inner paragraph'
)),
)),
))
);
I am trying & learning to build custom block for Gutenberg but spent a few hours on searching for full list of "available options". Maybe I was overlook...
Refer: Template and Block
For example, placeholder
& align
are options but what else?
function myplugin_register_book_post_type() {
$args = array(
'public' => true,
'label' => 'Books',
'show_in_rest' => true,
'template' => array(
array( 'core/image', array(
'align' => 'left',
) ),
array( 'core/heading', array(
'placeholder' => 'Add Author...',
) ),
array( 'core/paragraph', array(
'placeholder' => 'Add Description...',
) ),
),
);
register_post_type( 'book', $args );
}
add_action( 'init', 'myplugin_register_book_post_type' );
Example 2:
those empty array()
should be allow to store some options, right?
$template = array(
array( 'core/paragraph', array(
'placeholder' => 'Add a root-level paragraph',
)),
array( 'core/columns', array(), array(
array( 'core/column', array(), array(
array( 'core/image', array() ),
)),
array( 'core/column', array(), array(
array( 'core/paragraph', array(
'placeholder' => 'Add a inner paragraph'
)),
)),
))
);
Share
Improve this question
edited Apr 24, 2019 at 3:43
kevinckc
asked Apr 24, 2019 at 3:38
kevinckckevinckc
731 silver badge7 bronze badges
1 Answer
Reset to default 8Option 1
Browse the block-library
package in the Gutenberg's GitHub repository, and find the block metadata in a JSON file named block.json
of the specific block. For example, for the core/image
block, you can find the metadata (e.g. all available/supported attributes) here:
https://github/WordPress/gutenberg/blob/master/packages/block-library/src/image/block.json
So basically, the URL format is:
https://github/WordPress/gutenberg/blob/master/packages/block-library/src/{name}/block.json
where {name}
is the block name without the core/
part.
Option 2 (PHP)
For blocks registered using the PHP/WordPress function register_block_type
, you can use this to get the block attributes:
$block = WP_Block_Type_Registry::get_instance()->get_registered( 'core/latest-posts' );
$attrs = $block ? $block->get_attributes() : [];
var_dump( $attrs, $block );
Option 3 (JavaScript)
For blocks registered using the JavaScript function wp.blocks.registerBlockType
, you can use this to get the block attributes:
var block = wp.blocks.getBlockType('core/gallery');
var attrs = block ? block.attributes : {};
console.log( attrs, block );
本文标签: Looking for all available options of Gutenberg Block
版权声明:本文标题:Looking for all available options of Gutenberg Block 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745560953a2156160.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论