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

Idea: Add support for custom theme template file to be used for offline page #50

Closed
roborourke opened this issue Aug 9, 2018 · 6 comments · Fixed by #53
Closed

Idea: Add support for custom theme template file to be used for offline page #50

roborourke opened this issue Aug 9, 2018 · 6 comments · Fixed by #53
Milestone

Comments

@roborourke
Copy link

roborourke commented Aug 9, 2018

Although you can use a regular page as the offline page and choose a page template it might be desirable to let theme authors create a template file specifically for offline use as it could be quite different, eg. with no menus etc.

There are a couple of suitable options for this:

  • 503.php - service unavailable, also send the same status code? Not sure this is technically accurate to use, as it could be either the site or user who is offline
  • offline.php - not status code specific and self explanatory
@westonruter
Copy link
Collaborator

There was some discussion about this in #9 (comment)

However, the previous discussion was about using a custom template instead of having a page designated as the offline page. What I think you are suggesting is actually extending the template hierarchy to be able to select an offline.php for the offline page request (if a custom page template isn't already selected). I think that makes sense.

Not sure this is technically accurate to use, as it could be either the site or user who is offline

That's a good point, and it's related to #23 (comment).

I don't think we'd want to provide a UI to select a page both for when the client is offline and when the server is offline, but if there were two separate template files which are served in these two different scenarios than this would be a way to easily show a different message based on why the page is not accessible, without requiring that the offline page be communicating with the service worker to determine the cause of the error.

Note that this would require that precaching in #48 to request two separate URLs to cache, one URL for the page template used for offline and another for the 503 response. Perhaps a query var could be used to specify which template should be used when requesting the offline page. Nevertheless, if you select a custom page template should this not override the page template hierarchy? What if you want to select the page template for the offline case, but not for the 503 case?

@nico-martin
Copy link
Contributor

I think that would be a great compromise. We could add an offline.php detection. If the theme has an offline.php, the user should not be able to select an offline page. So the select box could be disabled an there could be a short text that explains that the offline.php will be used instead.

And since this is optional we can expect from the theme author to add the assets from the offline.php to the SW through the API.

@westonruter
Copy link
Collaborator

westonruter commented Aug 10, 2018

I wasn't thinking this specifically. Rather, that the offline.php template would be included with whatever the selected offline page as the queried object. But if they didn't select an offline page, then the offline.php template could be included and have_posts() would be false. Otherwise, if they did select an offline page then have_post() would be true.

@roborourke
Copy link
Author

if they didn't select an offline page, then the offline.php template could be included and have_posts() would be false. Otherwise, if they did select an offline page then have_post() would be true.

This makes sense to me, and sorry I missed the earlier discussion about it too - forgot to look through closed issues!

@westonruter
Copy link
Collaborator

As noted in #52 the direction now is to not have a user-specified offline page but rather to only use a static offline.php (and 500.php) template (similar to how 404.php is used). When not present in the theme, they would be pulled from wp-includes/theme-compat similar to how the embed template is handled. So importantly, the offline/500 error template hierarchy would not ever fall back to index.php in the theme.

So in this case, what I said in #50 (comment) is not relevant anymore, as there would be no queried object for the error template, unless a plugin introduces the ability for the user to select a page to serve offline.

@roborourke
Copy link
Author

Thanks for the update @westonruter, this sounds perfectly logical to me.

@westonruter westonruter added this to the 0.2 milestone Apr 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants