-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Extend Block Style Variations to Support Setting Block Settings #24994
Comments
Hello! This is precisely the reason behind the full variations API, which seems like it would cover this use case pretty well. There's not much documentation, but can be checked here: #20581 and @richtabor also did a nice post https://richtabor.com/block-variations/ Block Variations generally allow to register a set of attributes for any block, including nested blocks. The variations can be exposed in the placeholder state (different defaults) or as their own block in the inserter through the API. There's a pending task for also exposing them in the sidebar after you have created a block. |
Thanks for the reply, @mtias. I have to say that even after reading the Block Variations dev note in 5.4, this is the first time I really understand the feature and how it's intended to work. It seems there's a lot to be gained by improving the documentation and developer visibility of this feature. One possible drawback that I think I saw confirmed in @richtabor's tutorial is that you can't register variations for Core blocks. There also seems to be a big focus on Being able to provide preset configuration options (along with a custom class) for Core blocks is the primary goal of this request. If that means closing it in favor of another one, that's fine, so long as you can capture the real-world use cases. |
Definitely a lot of room to improve the docs! The feature does work for any block, including core blocks (you can register a block variation for |
Going back, I realize now that I misread a comment in the tutorial. It seems like there's some additional stuff required to provide the UI like Columns has, but that doesn't mean the variations won't work without it. Thanks for the clarifications. |
No worries! There's a ton of room to improve the documentation and communicate that this functionality does indeed exist, so thanks for the issue. |
#25231 Addresses the request in this ticket for improving the UI for to allow for switching between block variations. Given the I also know people have mentioned the confusion between style variations and variations. If it were me, I'd rename to Block Styles and Block Configurations. |
I'm closing this ticket since block variations meet this need. I do think a I will say though that I still find that fairly experienced developers are still unaware of block variations. |
Block Style Variations have been a fabulous, easy, lightweight way to enable theme authors to give users access to interesting styles. However, there are times when the styles either overlap with or require being used in combination with other block settings.
For example, a button style might work best with a specific border radius or a Cover block style might only work with a fixed position background. A real-world example of this can be found in this support comment excerpted here:
I believe this could be solved by support a third attributes parameter to
register_block_style()
. Some non-functional examples of what this might look like:or this
Alternatives Considered
Include all required styles in a single
.is-style-...
selectorThis is a bad idea as some styles like background color or border radius may conflict with block settings, creating a very confusing user experience. At its most extreme, a theme author could make certain styles
!important
, thereby preventing a block setting from having any impact on a block's appearance.Block Patterns
Block Patterns sort of solve this problem right now, but have a couple significant drawbacks.
Fundamentally, Patterns and Style Variations serve different purposes. I believe that supporting the ability to specify block attributes as part of a defined style is consistent with the intent of the feature and likely to provide an even better user experience.
The text was updated successfully, but these errors were encountered: