developer-blog-content icon indicating copy to clipboard operation
developer-blog-content copied to clipboard

How to add a template via a plugin (podcast, woo, LMS)

Open bph opened this issue 2 years ago • 5 comments

Discussed in https://github.com/WordPress/developer-blog-content/discussions/185

Originally posted by bph December 14, 2023 This question came up quite a bit in the last few months. Example It might not be possible, as I still see this issue open: Add support for adding templates and template parts for plugins #42362

So this is more a placeholder Topic idea, when this is worked out in core.

bph avatar Dec 19 '23 09:12 bph

This is the original issue https://github.com/WordPress/gutenberg/issues/41401

bph avatar Dec 19 '23 09:12 bph

These Fukken Feelings Podcast©. You can find us on ALL Podcast Platforms and don't forget to follow us on all social media platforms @fukkenfeelings to stay up-to-date on all new episodes and behind-the-scenes content.

petrio-seo avatar Jan 23 '24 13:01 petrio-seo

I have a solution for this: https://gist.github.com/justintadlock/cfcdcdf47ea785e84c8575dddc68ea37

There are several possibilities that could be explored based on the code in that Gist. It's specific to virtual pages, which is what I'm assuming is the biggest pain-point. But there are things that plugins can do now to make their "regular, non-virtual" templates editable in a block theme.

Anyone is welcome to take this code and run with it. I don't know what kind of bandwidth I'll have to fit another tutorial into my schedule in the immediate future, so I'll leave this topic unclaimed. But if no one picks it up, I'm OK with adding it to my list after the WP 6.5 update is out.

justintadlock avatar Feb 21 '24 17:02 justintadlock

Just an update from my end: I still have #238 and #239 to work through over the next few weeks. After that, I'm happy to take this one on. It might be mid-to-late April. But I'll leave this unassigned in case someone wants to try their hand at it.

justintadlock avatar Mar 21 '24 03:03 justintadlock

Chiming in here that this PR is very much underway: https://github.com/WordPress/gutenberg/pull/61577

annezazu avatar Jun 06 '24 17:06 annezazu

I'm working on this here: https://docs.google.com/document/d/1df9U3h5umMpbIEXRp4K38F9oFXDRPAi_4VPvt0houGg/edit?usp=sharing

Test code currently here: https://github.com/justintadlock/devblog-plugin-templates

justintadlock avatar Aug 15 '24 20:08 justintadlock

That's really cool, @justintadlock! Thanks for working on this. I see you used the .php extension for template files, is there any benefit of doing so instead of .html?

Aljullu avatar Aug 19 '24 07:08 Aljullu

@Aljullu - Because the files have PHP code in them for things like internationalization. This is pretty typical when building default templates.

justintadlock avatar Aug 19 '24 12:08 justintadlock

@Aljullu - Because the files have PHP code in them for things like internationalization. This is pretty typical when building default templates.

Oh, right, I missed the PHP snippets in some of them. It makes sense. :+1:

Aljullu avatar Aug 19 '24 12:08 Aljullu

This one is ready for its first review: https://docs.google.com/document/d/1df9U3h5umMpbIEXRp4K38F9oFXDRPAi_4VPvt0houGg/edit?usp=sharing

@Aljullu - Any technical feedback you'd like to share is more than welcome as well.

Note: If testing code, this requires Gutenberg 19.1. Also, the post cannot be published until that version of Gutenberg is live.

justintadlock avatar Aug 22 '24 20:08 justintadlock

I didn't test the code examples, but I read through it and everything looks good. Thanks for writing it, @justintadlock!

Aljullu avatar Aug 23 '24 11:08 Aljullu

@justintadlock I completed the first review of the article and added a few comments. Looks great.

ndiego avatar Aug 23 '24 14:08 ndiego

Moving this to second review.

We still have a couple of comments from the first review waiting for clarification/feedback in this ticket: https://github.com/WordPress/gutenberg/pull/61577

justintadlock avatar Aug 23 '24 17:08 justintadlock

Finished second review. Just tiny little nitpicks. It's ready to publish

bph avatar Aug 28 '24 16:08 bph

Social copy:

Coming in WordPress 6.7: Learn how to register block templates for plugin's custom post types, custom URLs, and more in this Developer Blog tutorial:

https://developer.wordpress.org/news/2024/08/29/registering-block-templates-via-plugins-in-wordpress-6-7/

justintadlock avatar Aug 29 '24 15:08 justintadlock

Social post scheduled for September 4.

justintadlock avatar Sep 02 '24 20:09 justintadlock