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

POC Use WordPress's new template mechanism #1594

Closed
wants to merge 12 commits into from
Closed

Conversation

Inwerpsel
Copy link
Contributor

@Inwerpsel Inwerpsel commented Jan 26, 2022

This adds an Author page template using a new template mechanism in WordPress. I hope one day each of these mechanisms will get a clear own name, but for now we need to explain in more detail to avoid confusion.

This mechanism works by checking the block-templates directory for a file with a certain name. For example author.html for the Author page.

It's checked before any of the other mechanisms, so I didn't have to remove author.php which it would use if we didn't provide this new file.

There's just 1 problem, but a big one. We have a lot of elements of our site in Twig templates, in fact most of them. Ideally all of these should be converted to blocks so that we can just add those blocks to the new WP template files.

But that's a lot of work before we can start using this. To get around the limitation, I created a new "Framework" block which holds the entire Planet4 UI, except the content part. The content is created by rendering the block's inner blocks to a HTML string and output it raw in Twig.

This was surprisingly easy and could directly render the base.twig template with almost no modification.

Observations

  • To fully create the author page currently it misses a block to output author name as a title. Should be relatively easy to create this block ourselves as we only need to define a back end render function for this use case.
  • An author bio block exists but it's more created as a secondary element on a post page. Maybe only needs styling changes.
  • "Inherit from template" Query Loop block seems to work for the author page. Still need to confirm other page types.
  • Pagination works and uses the items per page defined in WP's reading settings. On the test instance I changed this to 12 to better line out.
  • By default it uses the path and not a query string for the page numbers. Which is nice because it makes caching easier. We can just invalidate all pages from cache every time any list entry is added, changed, or removed. Could be the CF plugin already does this to some extent.

Test instance demo

I imported data from Denmark. Keep in mind that the author IDs on posts are not updated, so the author will change to whatever user has that ID on the test instance.

WordPress docs

Gutenberg repo related issues

Other WP themes that use this feature

planet-4 added a commit to greenpeace/planet4-test-venus that referenced this pull request Jan 26, 2022
/unhold 26863cb0-a676-4783-8218-355dfcc81d9d
planet-4 added a commit to greenpeace/planet4-test-venus that referenced this pull request Jan 26, 2022
/unhold d42767d1-94c2-4240-861b-425aacc4a090
@Inwerpsel Inwerpsel changed the title Allow inserting raw HTML in base template Use WordPress's new template mechanism Jan 26, 2022
@Inwerpsel Inwerpsel changed the title Use WordPress's new template mechanism POC Use WordPress's new template mechanism Jan 26, 2022
@planet-4
Copy link
Contributor

planet-4 commented Jan 27, 2022

Test instance is ready 🚀

🌑 venus | admin | blocks report | CircleCI | composer-local.json

⌚ 2022.02.11 15:05:16

planet-4 added a commit to greenpeace/planet4-test-venus that referenced this pull request Jan 27, 2022
/unhold 417fbc61-d9f2-4019-a5b3-54bc6a8b200f
planet-4 added a commit to greenpeace/planet4-test-venus that referenced this pull request Jan 27, 2022
/unhold 45a8d492-3264-40a7-b073-561f89001986
planet-4 added a commit to greenpeace/planet4-test-venus that referenced this pull request Jan 27, 2022
/unhold a3e61daf-2e6b-468c-8b57-4ae6a02aacd5
planet-4 added a commit to greenpeace/planet4-test-venus that referenced this pull request Jan 27, 2022
/unhold 8981ae35-4d86-4542-916e-9fc70127dafb
planet-4 added a commit to greenpeace/planet4-test-venus that referenced this pull request Jan 28, 2022
/unhold 7f67a908-c434-4c6f-82b3-1db9d2b31c4e
planet-4 added a commit to greenpeace/planet4-test-venus that referenced this pull request Jan 28, 2022
/unhold a5e59ba6-3334-4bf4-baa5-33b3f0eaceb6
planet-4 added a commit to greenpeace/planet4-test-venus that referenced this pull request Jan 28, 2022
/unhold 88f58466-3966-4c82-9840-611c7674be80
planet-4 added a commit to greenpeace/planet4-test-venus that referenced this pull request Jan 28, 2022
/unhold 0d8c34fb-da53-4a0f-994f-471dd69b20a6
planet-4 added a commit to greenpeace/planet4-test-venus that referenced this pull request Feb 9, 2022
/unhold 0b2ecc23-8e3e-493c-a1b0-8ca097deb38c
* This way we can generate the inner HTML using core blocks and output
it where it needs to be.
* First test with the new block-templates feature in WordPress. The
naming is terrible so here's a full description: templates added to the
block-templates directory are assigned by name to a certain type of
dynamic content pages.
* I created the page in the block editor and set the Query Loop block to
use "inherit query from template". It's unclear exactly how things such
as how many items per page need to be configured.
* The post title it gets on the author page is the author's latest
post's title. This is because WordPress uses some weird global
variables.
* Instead for now I'll make it use the author bio block, which is the
closest available.
* I might try to move some to template parts.
* Starting to look pretty close to the design.
* Almost identical to the author template, will move shared parts to
template parts later.
planet-4 added a commit to greenpeace/planet4-test-venus that referenced this pull request Feb 11, 2022
/unhold 559e36c5-68b0-4472-8c14-a858cef330ba
@comzeradd comzeradd closed this Jun 23, 2022
@comzeradd comzeradd deleted the add-some-templates branch June 23, 2022 07:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants