Ghost: Page previews are rendered in post template with 'post' context

Created on 2 Dec 2020  路  5Comments  路  Source: TryGhost/Ghost

The page context doesn't work for unpublished pages - the post context is used when previewing unpublished pages instead.

Additionally, unpublished pages when previewed also incorrectly display the default members CTA.

image

bug customer themes / frontend

Most helpful comment

@matthanley The fix is now in master :white_check_mark:

All 5 comments

The problem is that we're not aware if the resource is a post or a page when we render the preview at this point:

https://github.com/TryGhost/Ghost/blob/310ecd37c4433f4894952231f38bcb3352ef5d66/core/frontend/services/routing/controllers/preview.js#L63

There is an old todo about figuring out how to know which type of resource to preview:

https://github.com/TryGhost/Ghost/blob/310ecd37c4433f4894952231f38bcb3352ef5d66/core/frontend/services/routing/controllers/preview.js#L40-L42

To add a little more context to the problem. The template is picked based on the shape of the object that is passed down to template renderer:
https://github.com/TryGhost/Ghost/blob/4ef019d88d1c65d15d79b9c720f45218ea34e143/core/frontend/services/routing/helpers/templates.js#L187

And currently it is always of following shape:

{ 
    post: post 
}

https://github.com/TryGhost/Ghost/blob/4ef019d88d1c65d15d79b9c720f45218ea34e143/core/frontend/services/routing/helpers/format-response.js#L34-L49

The key part from above is:

 * In the future, we should return {page: entry} or {post:entry).
 * But for now, we would break the themes if we just change it.

Suggesting there are theme layer breaking changes to consider when trying to solve post vs page distinguishing problem.

This issue is related to https://github.com/TryGhost/Ghost/issues/10042.

I've checked the full lifecycle of the request and it looks like we loose the page/post type attribute at the serialization stage

https://github.com/TryGhost/Ghost/blob/4ef019d88d1c65d15d79b9c720f45218ea34e143/core/server/api/shared/pipeline.js#L246

Before serialization, there is a type attribute in the response object. I think one viable option is to keep this type attribute during the serialization

@matthanley The fix is now in master :white_check_mark:

@matthanley this fix landed in ghost 3.40.0

Was this page helpful?
0 / 5 - 0 ratings