Skip to content

Commit

Permalink
fix template resolution in site editor
Browse files Browse the repository at this point in the history
  • Loading branch information
ntsekouras committed Jan 15, 2024
1 parent d49d970 commit 690fc1e
Showing 1 changed file with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,25 @@ function useResolveEditedEntityAndContext( { postId, postType } ) {
return currentTemplate.id;
}
}

// If no template is assigned, use the default template.
let slugToCheck;
// In `draft` status we might not have a slug available, so we use the `single`
// post type templates slug(ex page, single-post, single-product etc..).
// Pages do not need the `single` prefix in the slug to be prioritized
// through template hierarchy.
if ( editedEntity.slug ) {
slugToCheck =
postTypeToResolve === 'page'
? `${ postTypeToResolve }-${ editedEntity.slug }`
: `single-${ postTypeToResolve }-${ editedEntity.slug }`;
} else {
slugToCheck =
postTypeToResolve === 'page'
? 'page'
: `single-${ postTypeToResolve }`;
}
return getDefaultTemplateId( {
slug: `${ postTypeToResolve }-${ editedEntity?.slug }`,
slug: slugToCheck,
} );
}

Expand Down

0 comments on commit 690fc1e

Please sign in to comment.