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

[Spike] Persist the BCPA home.html template through a theme switch #68427

Closed
autumnfjeld opened this issue Sep 29, 2022 · 20 comments
Closed

[Spike] Persist the BCPA home.html template through a theme switch #68427

autumnfjeld opened this issue Sep 29, 2022 · 20 comments
Assignees

Comments

@autumnfjeld
Copy link
Contributor

autumnfjeld commented Sep 29, 2022

Description

For the PA project pbxlJb-2ki-p2 there are some user experience problems that I hope we can address and hopefully would reduce some of the issues HE are reporting. Summarized here p1664345050428549/1664268210.013819-slack-CRWCHQGUB--this summary presents an ideal project, where we could build/make the changes needed to reduce user confusion.

This spike is about persisting a template and the template content after user does a theme switch. Matias opinion is that this isn't a difficult functionality to implement. However he mentions the "front page" template here (see screenshot). I would like to explore the idea of persisting a template for any template. There may be many types of solutions.

Image

An example of user flow

  • In BC theme (or any blockbase theme) create a custom template with content. (Or maybe this can be done programatically)
  • Switch themes
  • User should still be able to access their custom template in the new theme

Additionally, it could be that in the actual PA flow we'd save content to home.html, then during theme switch what would happen? There are many ways to approach this, so do what is most sensible.

ToDo

  • Report back on the technical path and estimated difficulty/time.
  • This can be done through research or a prototype.

Related / Info

@Automattic/ganon

@autumnfjeld autumnfjeld changed the title [Spike] [Spike] Persist a template through a theme switch Sep 29, 2022
@autumnfjeld
Copy link
Contributor Author

We should also look at persisting header and footer templates on theme switch: p1664377910901159/1664205177.351119-slack-C02M88KJ684

@bangank36 bangank36 self-assigned this Oct 3, 2022
@bangank36
Copy link
Contributor

bangank36 commented Oct 6, 2022

Regarding of themes switching, here is some note from Developer Resources

Block Template are custom post type wp_template, same for template parts wp_template_part

  • They are stored with a theme custom post meta to let us know which theme it comes from

Technically, we can store different theme value

I am putting together my research on a doc

@autumnfjeld
Copy link
Contributor Author

autumnfjeld commented Oct 10, 2022

@bangank36 @arthur791004

FYI: related, but not really something to worry about for this issue, just always good to be aware of core work. WordPress/gutenberg#25071


I think for this work, related to PA, this is the use case we want to handle:

  • user goes through PA flow
  • user gets theme Blank Canvas (or Clean Slate if that is the new name Initial Commit of Clean Slate themes#6665)
  • user makes changes to their template
  • user wants to switch theme, so we make sure template/content persists, perhaps it needs to be copied to a new template like blank-copy.html or clean-slate-copy.html. Because we don't want the template to conflict with a template in the new theme.

Note these are the templates in Onur's PR

image

@bangank36
Copy link
Contributor

@arthur791004, I think we can create a template without .HTML theme file right? I checked in endpoint wp/v2/templates and noticed 2 type of wp_template types can be saved into database

  • template which is attached to theme files ( CMIIW, template->source = custom )
  • template is created on fly, I think we can create this kind of template to persist old theme templates

@arthur791004
Copy link
Contributor

Yes, we could create any templates via the /wp/v2/templates endpoint and this PR is a great example to create a custom template.

template which is attached to theme files ( CMIIW, template->source = custom )

I believe the value of template->source is theme 😅

I think we can create this kind of template to persist old theme templates

I don't think so. We're not able to change the way that how we render the “Home“ page template, so you have to know how it works. See gutenberg_resolve_home_template.

In short, I guess the possible technical path for this one is to copy the content of the current “Home“ page template to the new one when the user switches between the themes using the “Home” page template (i.e. show_on_front = 'posts' or page_on_front === '0').

Note that the current “Home” page template means the template returned by gutenberg_resolve_home_template or resolve_block_template

Additionally, we also need to take care of the following cases:

  • switches from the theme using the “Home” page template to the theme using the Home page post
  • switches from the theme using the Home page post to the theme using the “Home” page template

@autumnfjeld
Copy link
Contributor Author

Additionally, we also need to take care of the following cases:

switches from the theme using the “Home” page template to the theme using the Home page post
switches from the theme using the Home page post to the theme using the “Home” page template

@arthur791004 Can you help me understand this?

Just focusing on when a user has gone thru PA flow and has the new blank canvas theme there won't be two cases. Right? There will only be one case: user switching from the BC theme which uses the home.html template to display content on the users root page. Then, on theme switech, we need to preserve the content of that template in the next theme.

In the case of themes like Pendant, Cultivate, Archeo, Yuga I think we must copy the content into a template that is not called home.html because these theme come with home.html. Correct me if I'm wrong about copying the content into a differently named template.

@arthur791004
Copy link
Contributor

Additionally, we also need to take care of the following cases:

  • switches from the theme using the “Home” page template to the theme using the Home page post
  • switches from the theme using the Home page post to the theme using the “Home” page template

I tested the above cases and the show_on_front keeps unchanged if the user wants to keep their home page content. As a result, we don't need to consider them.

I think we must copy the content into a template that is not called home.html because these theme come with home.html.

It depends. If the themes use “the latest posts” as their home page, the home page template might be “front-page.html”, “home.html” or “index.html”. Therefore, we need to copy the content from the old home page template to the new home page template. That is, we need to update the content of the new home page template with the original content.

@bangank36
Copy link
Contributor

bangank36 commented Oct 12, 2022

I tested the above cases and the show_on_front keeps unchanged if the user wants to keep their home page content. As a result, we don't need to consider them.

So we just need to preserve the content on home.html for PA flow right?

@autumnfjeld autumnfjeld changed the title [Spike] Persist a template through a theme switch [Spike] Persist the PABC home.html template through a theme switch Oct 13, 2022
@autumnfjeld autumnfjeld changed the title [Spike] Persist the PABC home.html template through a theme switch [Spike] Persist the BCPA home.html template through a theme switch Oct 13, 2022
@arthur791004
Copy link
Contributor

Not exactly. We need to preserve the home page template, and it might be one of “front-page.html”, “home.html” or “index.html”.

@autumnfjeld
Copy link
Contributor Author

So we just need to preserve the content on home.html for PA flow right?

Correct.
@arthur791004 @bangank36 We only need to implement this functionality for the PA flow and for the exact conditions of the PA flow / new Blank Canvas theme. Which is persisting content in the home.html.

The reason we won't implement this in other cases is because:

@fushar
Copy link
Contributor

fushar commented Oct 14, 2022

@autumnfjeld I think what @arthur791004 meant is that while it's true that we only need to persist the content of home.html from the PA Blank Canvas theme, we need to consider what template to updated in the destination theme as it could be one of “front-page.html”, “home.html” or “index.html”. CMIIW Arthur!

@arthur791004
Copy link
Contributor

Yes, that's what I mean. And we also need to consider switching back to the Blank Canvas theme, so the source of the home page template could be one of them too. We could use gutenberg_resolve_home_template to get the home page template in use

@autumnfjeld
Copy link
Contributor Author

Could you link the diff to this work here?

@bangank36
Copy link
Contributor

bangank36 commented Oct 17, 2022

Could you link the diff to this work here?

I made a draft diff D89996-code
I’ve learnt something about FSE, the wp/v2/templates is used to fetch the current site wp_template items, it is designated to filter templates based on wp_theme taxonomy, so only items that have the matched theme can be displayed on FSE template editor.
My attempt was to assign the extra wp_theme term to the home wp_template item, though there are some issues currently

  • The template names are the same, so upon editing FSE point to the same home template
  • Template parts linked to home template are broken
    image

What do you think @arthur791004 @fushar. We can keep the convo here since I can not reference to wpcom source code in github p1665982720077299-slack-CRWCHQGUB

@fushar
Copy link
Contributor

fushar commented Oct 21, 2022

so only items that have the matched theme can be displayed on FSE template editor.

I think this is OK... if the destination theme does not have e.g. header template part, then we don't have to copy the content over. Is this what you mean @bangank36 ? I think this is acceptable, what do you think @arthur791004 ?

@bangank36
Copy link
Contributor

header template part, then we don't have to copy the content over.

Yes, I agree.
So far I just loop over the blocks on the current home page and get the template-part that is part of the homepage and copy over new theme

@autumnfjeld
Copy link
Contributor Author

Demo from @bangank36 😃

theme-switch-demo-Screen.Capture.on.2022-10-18.at.08-49-00.mp4

@bangank36
Copy link
Contributor

Some theme is packed with custom patterns, but since we are just working new Blank Canvas theme with no patterns attached, I think we should not worry about that right now. How you think @autumnfjeld

@bangank36
Copy link
Contributor

bangank36 commented Oct 25, 2022

Some theme is packed with custom patterns, but since we are just working new Blank Canvas theme with no patterns attached, I think we should not worry about that right now. How you think @autumnfjeld

According to Ganon Sync on 10-25-2022, we decided to explore the possibility of supporting the persisting template for all other FSE-support themes, so I will dive into the solution to get the theme block pattern content and copy it into the new theme's template. 

Discussion is ongoing p1666672431670109-slack-CRWCHQGUB

@autumnfjeld
Copy link
Contributor Author

I'm going to close this spike issue.
The user facing feature is described here: #69421

Also related is this issue to persist pattern content for patterns that are theme-specific: #69507

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

No branches or pull requests

4 participants