$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>How to disallow a certain custom gutenberg block outside of an InnerBlocks block?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

How to disallow a certain custom gutenberg block outside of an InnerBlocks block?

matteradmin6PV0评论

I did add a custom block as an InnerBlocks block, called slider. Then i got another custom block slider-item. I think you get the idea.

The slider block just allows slider-item as it's child blocks. Like so:

<InnerBlocks
   allowedBlocks={ [ 'ajk/slider-item' ] }
   template={[
       [ 'ajk/slider-item' ],
       [ 'ajk/slider-item' ],
   ]}
/>

Now I want to achieve that an editor isn't able to use the slider-item outside of my slider container block.

Or is there some kind of repeater block possibility i do miss?!


WP 4.9.8

Gutenberg 4.2.0

I did add a custom block as an InnerBlocks block, called slider. Then i got another custom block slider-item. I think you get the idea.

The slider block just allows slider-item as it's child blocks. Like so:

<InnerBlocks
   allowedBlocks={ [ 'ajk/slider-item' ] }
   template={[
       [ 'ajk/slider-item' ],
       [ 'ajk/slider-item' ],
   ]}
/>

Now I want to achieve that an editor isn't able to use the slider-item outside of my slider container block.

Or is there some kind of repeater block possibility i do miss?!


WP 4.9.8

Gutenberg 4.2.0

Share Improve this question edited Nov 15, 2018 at 9:39 André Kelling asked Nov 2, 2018 at 14:27 André KellingAndré Kelling 1,0061 gold badge10 silver badges20 bronze badges 2
  • 2 The current documentation is lacking in this regard. Your best bet would be to ask on GitHub. You might get a response from devs - github/WordPress/gutenberg/issues – Ashiquzzaman Kiron Commented Nov 4, 2018 at 9:36
  • yes, hard to find right docs at the moment. – André Kelling Commented Nov 5, 2018 at 16:55
Add a comment  | 

1 Answer 1

Reset to default 7

In the slider-item you can specify parent must be slider. That way, the slider-item cannot be used outside of your slider container block.

Something like:

registerBlockType('ajk/slider-item', ...
  parent: ['ajk/slider'],

https://wordpress/gutenberg/handbook/block-api/#parent-optional

Post a comment

comment list (0)

  1. No comments so far