Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support subsets of block types in block templates #8142

Closed
mboynes opened this issue Jul 23, 2018 · 4 comments
Closed

Support subsets of block types in block templates #8142

mboynes opened this issue Jul 23, 2018 · 4 comments
Labels
[Feature] Templates API Related to API powering block template functionality in the Site Editor [Type] Enhancement A suggestion for improvement.

Comments

@mboynes
Copy link
Contributor

mboynes commented Jul 23, 2018

As a theme and plugin developer, I want to be able to define positions in block templates that are restricted to a subset of block types so that I can maintain structure in page templates while still supporting flexibility for similar media.


When defining block templates, I've found myself wanting to support multiple block types in a template position, which as best I can tell is not yet possible. A straightforward example of this is defining a region in a post that can be either an image or a video.

Examples

This is an example of one option for how we might define a region that could be either an image or a video, using a new block type block-set:

$post_type_object->template = [
    [ 'core/block-set', [
        [ 'core/image', [] ],
        [ 'core/video', [] ],
    ] ],
];
@ZebulanStanphill
Copy link
Member

Currently, the way you would do something like this is by using a block that only allows certain blocks as children, like the Media Area child block in #7414. Not sure if that is the best approach, though.

@designsimply designsimply added the [Type] Help Request Help with setup, implementation, or "How do I?" questions. label Jul 23, 2018
@designsimply
Copy link
Member

@mboynes are you able to do what you're after using child blocks?

@mboynes
Copy link
Contributor Author

mboynes commented Jul 24, 2018

@designsimply that's slightly different from what I'm suggesting -- or at least considerably more work. Going that route, and please correct me if I'm mistaken, requires one to create a custom block, in that custom block define the allowed child blocks, then use the new custom block in the template. I think this would be a useful enough feature to warrant core support, and not make developers go through that level of effort.

Possibly related: #7763, if InnerBlocks would eventually be used in the solution for this feature.

@designsimply designsimply added [Type] Enhancement A suggestion for improvement. [Feature] Templates API Related to API powering block template functionality in the Site Editor and removed [Type] Help Request Help with setup, implementation, or "How do I?" questions. labels Jul 25, 2018
@nerrad
Copy link
Contributor

nerrad commented Aug 11, 2019

I think you can now do something like what is requested here within template registration via InnerBlocks and also nested templates.

If that is not the case please feel free to comment with more details about your use-case. There's been a number of changes in the api since this issue was created and it's possible there may be an existing solution. (We can re-open this issue if necessary).

@nerrad nerrad closed this as completed Aug 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Templates API Related to API powering block template functionality in the Site Editor [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

4 participants