-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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 available page templates REST field and selector to sidebar #2086
Conversation
I used this PR to tweak the codecov settings so that it won't leave comments for PRs that don't change test coverage. (Right now, test coverage is only measured for JS code; separately, we should look into making codecov measure both JS and PHP coverage.) |
The code here seems like the most straightforward path towards exposing this information about page templates. However, I think some of it (the relationship between page templates and names, at least) might be a better fit for a theme endpoint. #991 (comment) mentions the If not for these filters, or if they are almost never used, then I would say the list of page templates is really a property of the active theme. Unfortunately, there's not yet a great place to expose information like that in the REST API, so taking it onto the page endpoints may still make the most sense for now. |
That was a typo on my part. I should have said
It's interesting to note that not only can Imagine the usefulness of having a list of front-page templates which are shown only for the page that is shown on front, and these same templates are not available for other pages. These can be accomplished via the
I don't know 😄 I'll run an |
@nylen there are 43 instances of this filter being used in themes and plugins: https://gist.github.com/westonruter/629aa2e2fd0eb74f70d6c3bfea92071f Some plugins that stand out to me which use the filter include: elementor, eventbrite-api, woocommerce. |
Dropping a note here after a discussion in Slack. What's the difference between theme templates and other theme options like color palette, wide-image setting. I tend to see those as just another theme setting. It just have a different way to declare this setting. So for now, we're using a config variable provided to the editor on init, we could use the same variable to provide the available templates. Having an endpoint for the theme settings makes sense too but I'd think it has to include several theme settings and not only the available templates. |
As noted above, I'm not a big fan of the data model here. I still think page template should be a property of a theme, and we should (separately) evaluate whether it's possible to get a list of all the available templates for a theme. If possible, listing all available templates, then occasionally failing to set the template with an error message like "This template is not available for this page" seems ok to me. Still, that's a much larger exploration, likely as part of a set of theme endpoints. So I think for now there are a couple of different options:
Given that we know the data model here isn't great, and we don't actually need to call out to the REST API and update this information beyond loading the initial content, I'm kind of leaning towards the second option, but would be interested in hearing about any drawbacks. |
I don't think this is possible since a plugin could supply any PHP file as being a page template for a specific page. In other words, there wouldn't be a way to get a lost of all possible templates without applying the filters on every page created in the DB and getting the combined set of all.
Yes, bypassing the REST API and exporting the available page templates for the given page among in the initial PHP exports makes sense to me. |
Closing this because @nylen's out-of-REST-API-band approach will work better. |
Layout Template Modal & Button block - Orientation fixes
See #991.
Note that the reason for adding an entire new field on the
page
resource is explained in #991 (comment). The page templates available for a page can vary from page to page due to thetheme_{$post_type}_templates
filter which is passed the page instance. This is the reason for adding a new field to thepage
itself. Note also that the list of page templates is already exposed on in the schema:However, the name of the template is not included. Therefore, the names are then included in this new field: