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

Post Excerpt: add previewPlaceholder attribute #49036

Closed

Conversation

gigitux
Copy link
Contributor

@gigitux gigitux commented Mar 13, 2023

What?

This PR adds the previewPlaceholder attribute. If defined, the block will show this latter as a placeholder. Also, I updated the default text following the suggestion in the issue.

Why?

As I explained in #48964, I'm more inclined to update the preview placeholder in this way:

This is the Post Excerpt block, it will display the excerpt from single {post_type}.

Unfortunately, retrieving the post type in a block is impossible. So, this is another approach to fixing the issue.

With this approach, a block developer can create a variation of the Post Excerpt block and customize the preview placeholder via the attribute.

Testing Instructions

  1. Create a variation of the Post Excerpt passing the previewPlaceholder attribute.
  2. Add the variation in a template (Post template, for instance) and ensure the custom preview is visible.

@Mamaduka
Copy link
Member

Hi, @gigitux

Using attributes for preview purposes isn't ideal. There's a similar discussion for the Site Title block - #48300 (comment).

@gigitux
Copy link
Contributor Author

gigitux commented Mar 14, 2023

Hi, @gigitux

Using attributes for preview purposes isn't ideal. There's a similar discussion for the Site Title block - #48300 (comment).

Hi, @Mamaduka, thanks for the review! 🙇
As I said, this is an alternative approach. I agree that the ideal solution is retrieving the post type in the block, but it is not possible. I wasn't able to find a GitHub issue for this (in this way, I can follow the progress and help if necessary). Do you know if it is there?

(I will close this PR)

@gigitux gigitux closed this Mar 14, 2023
@Mamaduka
Copy link
Member

@gigitux, I can't recall any general issue for improving the preview states for blocks that require entities. Maybe @ntsekouras does.

@ntsekouras
Copy link
Contributor

ntsekouras commented Mar 15, 2023

I don't think there is a general issue for this.. @gigitux could you create one?

The problem is twofold:

  1. Some blocks can be used by different postTypes, taxonomies/terms, etc.. (like this one) and the placeholder could use that information to show better descriptions/texts.
  2. When such blocks are used as top level blocks in site editor, that context might be missing and maybe we can infer them from templateSlug context(example)? 🤔

@gigitux
Copy link
Contributor Author

gigitux commented Mar 15, 2023

I don't think there is a general issue for this.. @gigitux could you create one?

I created #49108. I don't think one approach excludes the other, even if the block is used as a top-level in the site editor. What do you think?

The problem is twofold:

  1. Some blocks can be used by different postTypes, taxonomies/terms, etc.. (like this one) and the placeholder could use that information to show better descriptions/texts.
  2. When such blocks are used as top level blocks in site editor, that context might be missing and maybe we can infer them from templateSlug context(example)? 🤔

I didn't know anything about the templateSlug. Is there documentation about the context defined by Gutenberg? I knew query, queryId, and postId.

Do you think that using the templateSlug for the Post Title block could have sense? #48963

@ntsekouras
Copy link
Contributor

I didn't know anything about the templateSlug. Is there documentation about the context defined by Gutenberg? I knew query, queryId, and postId.

I don't think there is documentation about this, but templateSlug is set when we navigate through templates in site editor and an example usage is here.

Regarding the Post Title at first we should at least check if postType is in context and update the placeholder text. We could probably infer the postType by templateSlug and request the type to get the proper label too.

@gigitux
Copy link
Contributor Author

gigitux commented Mar 21, 2023

I don't think there is documentation about this, but templateSlug is set when we navigate through templates in site editor and an example usage is here.

Thanks for pointing me to the line of code 🙇

Regarding the Post Title at first we should at least check if postType is in context and update the placeholder text. We could probably infer the postType by templateSlug and request the type to get the proper label too.

I will work on this in the next weeks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants