Gutenberg: UI: Add Page Templates

Created on 2 Jun 2017  路  26Comments  路  Source: WordPress/gutenberg

When you use the editor to edit a page, you need to be able to pick a template, set the order, and parent.

Those three properties are very likely to change in the future. But they are nonetheless important to be able to set in a transitional period.

What's the best way to approach this?

Here's a quick mockup of a transitional metabox that would be good to retire once something superior can replace it:

screen shot 2017-06-02 at 09 44 37

post settings

Core REST API Task Gutenberg Plugin

Most helpful comment

I'd like to see, probably in v2, page templates that specify the blocks that they allow, their order, how many of each type, and so on. When they do these blocks then get added to the editor as locked. This could be added to the page template metadata PHP docblock comment.

All 26 comments

The Order field should be a [type="number"] input instead of a dropdown, by the way. Drop-down doesn't really make sense for numerical values, as you could be thousands of options.

The Order field should be a [type="number"] input instead of a dropdown, by the way. Drop-down doesn't really make sense for numerical values, as you could be thousands of options.

That was bad mockup copy/pasta on my part, sorry :) I meant for it to be a plain input field, but type="number" is even better.

Hm I'm not sure about the [type="number"] while technically it would be appropriate, we're discussing them in the accessibility team since it seems it's not widely supported by assistive technologies 馃槥 More details here: https://make.wordpress.org/accessibility/2017/02/13/testing-html5-type-attributes-in-forms-with-different-browsers-and-at/

[type="number"] seems problematic especially with speech recognition software (Dragon), more details here: https://make.wordpress.org/accessibility/2017/01/16/testing-form-functionality-with-different-assistive-technology/

we're discussing them in the accessibility team since it seems it's not widely supported by assistive technologies 馃槥 More details here: https://make.wordpress.org/accessibility/2017/02/13/testing-html5-type-attributes-in-forms-with-different-browsers-and-at/

My takeaways from this post are: validation isn't always reliable (maybe not a blocker?), shows a small input by default (could be resolved by styling or size attribute?). Anything I overlooked?

[type="number"] seems problematic especially with speech recognition software (Dragon), more details here: https://make.wordpress.org/accessibility/2017/01/16/testing-form-functionality-with-different-assistive-technology/

That's a shame. If this becomes a blocker, maybe it could be enough to recreate the effect with a text type, numeric pattern attribute, and manually bind to the keyboard events to simulate increment effects?

This is something that needs to be added. For v2 we'll rethink how you select templates, maybe with an upfront selection process like when creating a new slide in keynote or pages document.

I'd like to see, probably in v2, page templates that specify the blocks that they allow, their order, how many of each type, and so on. When they do these blocks then get added to the editor as locked. This could be added to the page template metadata PHP docblock comment.

that specify the blocks that they allow

See also #1654

Added "Needs API Endpoint" label. To my knowledge, there's currently no way to retrieve available page templates from the REST API.

Something else to note is that the list of available page templates can actually vary from page to page, due to the theme_{$post_type}_templates filter. So the endpoint would need to hang off of the page resource itself, like: /wp-json/wp/v2/pages/:id/available-templates

@aduth I've started a PR (#2086) to add a new available_page_templates field to the page resource which we can use to obtain the available templates _and their names_ for use in a page template selector.

Punting.

From my understanding #2086 has been closed. I can take this up.

This is important to have, let's try to work on this soon.

Just wondering about the status of including page templates. I just downloaded the recent version and there is no where to choose a page template. I like idea of adding certain blocks based on a CPT but there are plenty of times where there is NO CPT created but I still need to use a custom template. So just checking on the status of how and when the ability to choose a custom template from the Gutenberg editor.

screen shot 2017-12-25 at 6 21 05 am

I would like to see this functionality too!

@brothman01 This feature has since been implemented, so it should be available for you to use. If you're not seeing the option, can you verify that you're editing a page? Can you provide more information about the theme you're using, and which page templates you're expecting to see?

aduth, thanks for the information. Yes it is showing up now.

Thanks!

Still not seeing it, running Gutenberg 3.7 on WordPress 4.9.8

@gmariani Make sure that your theme is loading at least one page template, because if your theme is not, then it won't show up.

@ajvillegas I am also not able to see any page template selectors, and I'm pretty sure that my theme is loading up a template. I'm just using a modified version of twentyseventeen.

I'm not seeing it either, and I KNOW there are page templates on the site/theme I'm editing. The site and theme in question have not changed in any way other than the update to WP5, so clearly this is a WP5/Gutenberg issue.

(And FWIW, I actually love Gutenberg, can't wait for it to be perfect.)

@jcklpe @ChazzLayne If possible, could you provide a set of steps that someone could follow to reproduce the issue? Particularly considering whether there's a specific (publicly-available) theme / post type combination under which valid templates are not appearing.

It may be worth providing these as part of a new issue targeted at missing templates, rather than continuing the discussion here, since it will be more visible / actionable that way.

WordPress 5.0.3 running Twenty Nineteen theme. No template options in Add New Page. :(

@stellalabella The Twentynineteen theme does not include any custom page templates, which is the likely explanation for them not being shown in the editor. The same can be seen in the classic editor using the Classic Editor plugin.

Update! I installed Sela theme which is known to have page templates, and it worked.

I have installed Wordpress 5.1. Template option is not available in Add new page also. I tried several themes just in case, and yet, none one of them got their template option displayed in the edit page. Only the parent page and order options were available.

Same here, no "Page Template" option under "Page Attributes", and I'm sure that I have a template file in my theme folder like "templatename.php".
Has this content:

/*
Template Name: templatename
Template Post Type: page
*/

Oh and the WordPress version is 5.3.2

That's weird.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

spocke picture spocke  路  3Comments

davidsword picture davidsword  路  3Comments

jasmussen picture jasmussen  路  3Comments

wpalchemist picture wpalchemist  路  3Comments

mhenrylucero picture mhenrylucero  路  3Comments