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

Using Patterns in Templates #21830

Closed
uamv opened this issue Apr 23, 2020 · 12 comments
Closed

Using Patterns in Templates #21830

uamv opened this issue Apr 23, 2020 · 12 comments
Labels
[Feature] Block API API that allows to express the block paradigm. [Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced [Feature] Templates API Related to API powering block template functionality in the Site Editor [Type] Enhancement A suggestion for improvement.

Comments

@uamv
Copy link

uamv commented Apr 23, 2020

I've begun tinkering with the experimental block patterns API and expected that I might be able to register patterns and then call upon those registered patterns alongside other registered blocks when defining the template of a CPT.

It'd be great to simply build a template using existing patterns. If this is not already possible in some way, I propose it be considered how to make such templating available.

// From the registration of a CPT
'template' => array(
  array( 'my-plugin/my-pattern' ), // including a pattern
  array( 'core/paragraph' ) // including a block
)
@annezazu annezazu added [Feature] Block API API that allows to express the block paradigm. [Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced labels Apr 23, 2020
@nachos5
Copy link

nachos5 commented Sep 10, 2020

This would be very useful, any plans to implement this?

@aandrewjoyce
Copy link

Would also be very interested in this.

@talldan
Copy link
Contributor

talldan commented Nov 9, 2021

I've closed #36323 as a duplicate of this.

That issue was encountered during a triage session in slack (https://wordpress.slack.com/archives/C02QB2JS7/p1636435134063000).

There was a suggestion there to use the newly introduced pattern block in the template (see #33217).

That block has a slug attribute that can be used to reference a pattern - https://github.com/WordPress/gutenberg/blob/trunk/packages/block-library/src/pattern/block.json#L13.

@uamv @nachos5 @aandrewjoyce ethanclevenger91 It'd be good to get your feedback on whether this option will work for you. Thanks!

@talldan talldan added the [Feature] Templates API Related to API powering block template functionality in the Site Editor label Nov 9, 2021
@illycz
Copy link

illycz commented Dec 7, 2021

Fantastic! I'm using it for post type block template.
It's solve also #33379

Thanks

@troytempleman
Copy link

troytempleman commented Dec 30, 2021

The pattern block works as a CPT 'template' for me too, but unfortunately I can't lock it the same way as I could before with an array version of the template.

As soon as I add 'template_lock' => 'all' to the CPT, the template layout disappears and reverts to default.

Maybe I'm doing something wrong though. Does anyone have a working solution to locking a pattern?

Thanks!

@jordesign
Copy link
Contributor

Hey @troytempleman - just checking in on this - did you ever find a way to get it working with Template Lock?

@troytempleman
Copy link

@jordesign no sorry, I’ve since gone down a block plugin rabbit hole that I’m still in, lol. Will probably be revisiting block themes/templates soon though.

@jordesign
Copy link
Contributor

Given that much has changed in the past couple of years - I'll close this issue as not current. But if you do run into problems again in the future please feel free to open a new issue with updated details.

@jordesign jordesign closed this as not planned Won't fix, can't repro, duplicate, stale Aug 21, 2023
@bvlgn
Copy link

bvlgn commented Sep 18, 2023

@jordesign But although much changed there is still no complete solution when it comes to the template lock.
If e.g. you set template_lock to 'contentOnly' when using the pattern block in the template, to work around the issue, the pattern blocks won't be loaded. Because inserting is locked and that is how the pattern block injects the blocks that are part of the pattern.

I would like to request this to be reopened in the hope some dev will be able to come up with a solution that handles template lock as expected.

@jordesign jordesign reopened this Sep 18, 2023
@jordesign jordesign added the [Type] Enhancement A suggestion for improvement. label Sep 18, 2023
@ouw-jvt
Copy link

ouw-jvt commented Oct 24, 2023

Absolutely want this feature! It almost works right now, but you have to toggle the code editor on/off in order for the pattern to render.

@mikeybinns
Copy link
Contributor

I also would like to see this done. Seems potentially related to / could use the same solution as #49005

@talldan
Copy link
Contributor

talldan commented May 16, 2024

But although much changed there is still no complete solution when it comes to the template lock.

I think this is possible, you can wrap the pattern contents in a group block (so that the group is the top level block inside the pattern) and use the templateLock attribute of the group block.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Block API API that allows to express the block paradigm. [Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced [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