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

Feature request: Allow registering custom block styles for template parts #31171

Open
carolinan opened this issue Apr 25, 2021 · 4 comments
Open
Labels
[Block] Template Part Affects the Template Parts Block [Feature] Site Editor Related to the overarching Site Editor (formerly "full site editing") [Feature] Theme Style Variations Related to style variations provided by block themes [Type] Enhancement A suggestion for improvement.

Comments

@carolinan
Copy link
Contributor

I would like to be able to offer custom block styles for the site header, that are not available for other generic template parts.

register_block_style(
	'core/template-part/slug-that-matches-template-part-name',
	array(
		'name'  => 'prefix-box-shadow',
		'label' => __( 'Box shadow', 'textdomain' ),
	)
);
@carolinan carolinan added [Type] Enhancement A suggestion for improvement. [Feature] Theme Style Variations Related to style variations provided by block themes labels Apr 25, 2021
@justintadlock
Copy link
Contributor

I've been thinking about this a bit. What about doing this based on the template part "area" too?

What I find myself needing is the ability to register styles for all header template parts and not just one.

@carolinan carolinan changed the title Feature request: Allow registering custom block styles for named template parts Feature request: Allow registering custom block styles for template parts Jul 24, 2023
@annezazu annezazu added [Feature] Site Editor Related to the overarching Site Editor (formerly "full site editing") and removed [Feature] Full Site Editing labels Jul 24, 2023
@carolinan
Copy link
Contributor Author

It is possible to register a style for template parts, but not area specific parts.
It may not be a good idea, since the user can not customize any template part styles. The block has no controls.

It may be a better option now to register style variations (section styles) for containers like groups, which are inside the template parts. The downside is that I have to click on "Edit" in the toolbar of the template part before selecting a style.

This json variation works when placed in the styles folder of a block theme:

{
	"$schema": "https://schemas.wp.org/trunk/theme.json",
	"version": 3,
	"title": "test",
	"slug": "header",
	"blockTypes": [ "core/template-part" ],
        "styles": {
		  "color": {
			  "background": "red"
		  }
	  }
}

But this does not work:

{
	"$schema": "https://schemas.wp.org/trunk/theme.json",
	"version": 3,
	"title": "test",
	"slug": "header",
	"blockTypes": [ "core/template-part/header" ],
	"styles": {
		"color": {
			"background": "red"
		}
	}
}

@carolinan
Copy link
Contributor Author

@justintadlock shall I close this issue in favor of styling the container blocks?

@justintadlock
Copy link
Contributor

I don't know. I still like the idea, but I've pretty much just been using block styles for nested container blocks for a long while now. I think that's probably just going to become the de facto standard method because themers and users haven't had a choice but to use an alternative solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Template Part Affects the Template Parts Block [Feature] Site Editor Related to the overarching Site Editor (formerly "full site editing") [Feature] Theme Style Variations Related to style variations provided by block themes [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

3 participants