Examples: Using nodeByUri
to replicate WP template hierarchy
#854
Replies: 6 comments 5 replies
-
We have been giving this some thought in how we could support this. What you said about the WordPress to headless dev is spot on. The tricky part here is rendering the appropriate template. Dynamic imports with variables is not possible in Webpack, which makes things challenging when trying to replicate the more specific cases in the WP template hierarchy (for example FWIW, I recently tried this out with a Next.js custom server, and got the full WP Template Hierarchy routing resolving properly by replacing the native Next.js router with a custom one that gets the |
Beta Was this translation helpful? Give feedback.
-
Just confirming: the need for dynamic components is because without pages we don't get any chunking? Im still whetting my teeth with NextJS, but I was under the impression that that dynamic imports with template literals instead of variables work fine. I don't know enough about the performance implications or the interplay with gqty, but my assumption has been that as long as there's a dedicated Jw: if performance is the sole concern, then maybe it's valid not to care? Meaning have |
Beta Was this translation helpful? Give feedback.
-
Referring to this Next.js doc page:
I think in regards to this, perf is unrelated; getting these components that follow the WP Template Hierarchy dynamically imported seems to be the main struggle. |
Beta Was this translation helpful? Give feedback.
-
Does this workaround not work? I guess as a NextJS noob, I'm trying to understand why we need dynamic imports at all, if it's not "just" a performance thing? |
Beta Was this translation helpful? Give feedback.
-
@justlevine In the upcoming version of Faust.js (coined FaustNX) for now we have an experimental support for WP's template hierarchy using conventional component approach. You can take a look at an example project here> |
Beta Was this translation helpful? Give feedback.
-
@justlevine Alternatively you can use the default faust-nx example project The installation instructions are like:
|
Beta Was this translation helpful? Give feedback.
-
It would be great to see an example of implementing WP's template hierarchy with next+Faust.js.
For WP-to-headless devs, a big part of the transition is trying to implement everything WP gives you for free (also arguably a strong impetus for headless devs choosing WP as a backend), and both types of devs could benefit from some more advanced gqty examples.
An ideal example would:
pages/index.tsx
that usesnodeByUri
for hydration.post
,page
andtaxonomy
types on thenodeByUri
interface.<Template.Home />
,<Template.Page />
,<Template.Singular />
, and maybe a custom template like<Template.FullWidthTemplate />
<Header />
and<Footer />
.Beta Was this translation helpful? Give feedback.
All reactions