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

Add the ability to lock/make exclusive patterns to template parts #47208

Open
jonathan-dejong opened this issue Jan 17, 2023 · 5 comments
Open
Labels
[Block] Template Part Affects the Template Parts Block Developer Experience Ideas about improving block and theme developer experience [Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced [Type] Enhancement A suggestion for improvement.

Comments

@jonathan-dejong
Copy link

What problem does this address?

Presently it does not seem to be possible to create patterns that should be unique to a specific template part.
Say I'm building a hybrid theme where I am only using template parts but not templates.
I have a template part for my footer and I want to present the user with two variations of that footer.
I could create two patterns that represents all the blocks and layout of each variation.

However those patterns does not make sense to expose outside the editing of this template part, they just become clutter for the user.

What is your proposed solution?

The ability to actually lock down a pattern to only appear in the context of to which part of Gutenberg it has been assigned.
We already have template locking for templates and individual blocks so to me it makes sense to utilise the same standard on this.
So similarly to how you can set blockTypes on registering a pattern you could also set templateLock.

register_block_pattern(
	'wpdocs-my-plugin/my-awesome-pattern',
	array(
		'title'        => __( 'Two buttons', 'wpdocs-my-plugin' ),
		'description'  => _x( 'Two horizontal buttons, the left button is filled in, and the right button is outlined.', 'Block pattern description', 'wpdocs-my-plugin' ),
		'content'      => '',
		'templateLock' => array( 'core/template-part/footer' ),
	)
);
@kathrynwp kathrynwp added [Type] Enhancement A suggestion for improvement. [Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced [Block] Template Part Affects the Template Parts Block labels Jan 17, 2023
@annezazu
Copy link
Contributor

This feels related to #45814 and #45285 cc @jorgefilipecosta as a heads up!

@annezazu annezazu added the Developer Experience Ideas about improving block and theme developer experience label Jan 19, 2023
@annezazu
Copy link
Contributor

To understand a bit better, is there a reason you wouldn't want to create two footer template parts that a user could pick between?

@jonathan-dejong
Copy link
Author

Please note that I am talking about a so called "hybrid" theme in this issue.
So a theme that does not have a templates/ directory and the index.html file.

So if I am to allow the selection of separate template parts for the same section I would need to come up with my own way of letting the admin pick which template to render in a specific location.
Because I would be using the block_template_part() function in a theme php template file.
https://developer.wordpress.org/reference/functions/block_template_part/

If I was developing a full FSE theme I think you are right, I could probably just have two different footer template parts and then let the admin choose which one they want to assign to the footer template 🤔

But in this case I need to work with a single template part, but have restricted options for what to add into that area.

Does that make more sense?

@annezazu
Copy link
Contributor

But in this case I need to work with a single template part, but have restricted options for what to add into that area.

Yes! Totally makes sense. This should be improved when we add this option too: #44582

@jonathan-dejong
Copy link
Author

Yes that looks interesting!

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 Developer Experience Ideas about improving block and theme developer experience [Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

3 participants