-
Notifications
You must be signed in to change notification settings - Fork 134
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
Preview isn't working for frontpage #1914
Comments
Hello @MKlblangenois. Is your |
Hi @theodesp, yes, the template as the Component.query = gql`
query GetFrontPageData($asPreview: Boolean) {
...RootLayoutFragment
page(id: "/", idType: URI, asPreview: $asPreview) {
content
...FeaturedImageFragment
editorBlocks(flat: false) {
...BlocksFragment
}
... |
Thanks @MKlblangenois . Does your reading settings in WordPress point to a specific page? I was able to preview the front-page using by pointing to the HOME pages as a static page. This preview uses the page.js template instead of the front-page.js template. I'm not sure if its possible to trigger a preview on a HOME page otherwise. The seed query does not resolve to page content when I use |
Hi @theodesp, thanks for your following. My front-page is already set in reading settings like that: The problem here is that the preview of HOME use page.js template and not the front-page.js template. So, with that, the front-page preview doesn't take my GraphQL query from |
Hello @MKlblangenois. I think this happens because the preview on a HOME page resolves to a page.js when you try to preview it.
as you can see since the You might be able to add a custom hook to change the order of the possible templates list but I haven't tested that theory yet.
|
Hi @MKlblangenois, were you able to find a solution to this? I am also stuck with the same issue. |
Hi @theodesp, thanks for the lead, it actually works by manually adding the model. I just have a quick question that I didn't see in the docs. Is it possible to use an async function in the filter callback? I would like to retrieve the contentNode via the ID provided by the seedNode using GraphQL request, but the TS schema does not seem to go in this direction and doing so returns me a Promise Hi @felipesnts ! Yes, I was able to find a solution using // # faust.config.js
import { ExtendPossibleTemplateList } from "./plugins/possibleTemplateList";
// ...
export default setConfig({
templates,
plugins: [new ExtendPossibleTemplateList()],
// ...
}); // # ./plugins/possibleTemplateList.ts
import { FaustHooks, FaustPlugin } from "@faustwp/core";
export class ExtendPossibleTemplateList implements FaustPlugin {
apply(hooks: FaustHooks) {
const { addFilter } = hooks;
addFilter(
"possibleTemplatesList",
"nextpress",
(possibleTemplates, { seedNode }) => {
if (
seedNode &&
seedNode?.slug &&
seedNode?.slug?.includes("autosave")
) {
if (!seedNode?.uri) return possibleTemplates;
try {
const seedNodeURI = new URL(seedNode.uri);
const previewPath =
seedNodeURI.searchParams.get("previewPathname");
if (previewPath === "/") {
// Add front-page template
possibleTemplates.unshift("front-page");
}
} catch (e) {
console.error(e);
}
}
return possibleTemplates;
}
);
}
} Note This only work if you haven't i18n setup. It only works by checking if previewPathname is "/" (equal to isFrontPage on WordPress) |
I had the same issue. Here is the solution that worked for me: Interim Solution: I've managed to get around this by adding a page template for the home page and then just redirecting it to my 'front-page' template. I did seem to have a secondary problem where the template would load twice, once without data before the preview loaded properly. I resolved this by adding in a preview check at the top of the 'front-page' template.
The |
Description
When I try to reach the frontpage preview, I got my default page template, without data in props.
Other page and single works fine.
Steps to reproduce
Additional context
Result with console.log of
preview.tsx
props:Expected result:
@faustwp/core Version
3.0.1
@faustwp/cli Version
3.0.1
FaustWP Plugin Version
1.3.1
WordPress Version
6.5.4
Additional environment details
Please confirm that you have searched existing issues in the repo.
The text was updated successfully, but these errors were encountered: