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

Fix template display in page details with a custom template #51638

Merged
merged 2 commits into from
Jun 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ function getPageDetails( page ) {

export default function PageDetails( { id } ) {
const { record } = useEntityRecord( 'postType', 'page', id );

const { parentTitle, templateTitle } = useSelect(
( select ) => {
const { getEditedPostContext, getSettings } = unlock(
select( editSiteStore )
);
const defaultTemplateTypes = getSettings()?.defaultTemplateTypes;
const { getEditedPostContext } = unlock( select( editSiteStore ) );
const postContext = getEditedPostContext();

const templates = select( coreStore ).getEntityRecords(
'postType',
'wp_template',
{ per_page: -1 }
);
// Template title.
const templateSlug =
// Checks that the post type matches the current theme's post type, otherwise
Expand All @@ -112,10 +112,10 @@ export default function PageDetails( { id } ) {
? postContext?.templateSlug
: null;
const _templateTitle =
defaultTemplateTypes && templateSlug
? defaultTemplateTypes.find(
templates && templateSlug
ntsekouras marked this conversation as resolved.
Show resolved Hide resolved
? templates.find(
( template ) => template.slug === templateSlug
)?.title
)?.title?.rendered
: null;

// Parent page title.
Expand All @@ -135,7 +135,7 @@ export default function PageDetails( { id } ) {
templateTitle: _templateTitle,
};
},
[ record ]
[ record?.parent ]
);
return (
<VStack spacing={ 5 }>
Expand Down