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

Set view paths on each page, taking multi-site into consideration #129

Closed

Conversation

davebarrau
Copy link

@davebarrau davebarrau commented Mar 15, 2023

Fixes #127.

Currently if you have two sites in a multi-site setup, say, for example, default and test.

Using php please ssg:generate, if you attempt to generate a page that is part of the test site, the view path resources/views/test/ will never be added to the list of view paths to find files in, so you cannot override the layouts/partials/other files.

Because statamic/cms has the AddViewPaths HTTP middleware, it works when visiting the site, just not when using the static site generator. Ideally the logic currently in the AddViewPaths middleware would be split out so SSG can use the parts of it it needs, but this should hopefully be a sufficient improvement for now.

Co-authored by: @michaelr0

@what-the-diff
Copy link

what-the-diff bot commented Mar 15, 2023

  • Added a backupViewPaths() method to store the current view paths.
  • Added a restoreViewPaths() method to set the stored view paths back after generating static files for each site.
  • Updated createContentFiles(), updateCurrentSite($site), and shouldSetCarbonFormat($page) methods by adding calls to setViewPaths(). This is needed because we are changing the views directory when switching between sites, so it needs to be reset before rendering pages from other sites (e.g., pagination links).

@davebarrau
Copy link
Author

@jasonvarga When you get a chance, can you please review this? 🙇

Copy link
Member

@jasonvarga jasonvarga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not exactly sure of the reason (maybe it's a race condition?) but this doesn't always work.

For example:

If my home page uses a home template, and I've created a site-specific one for the second site (e.g. views/two/home.antlers.html) sometimes I will see site two's home template be used for site one's home page.

Since the pages are generated randomized, you may need to run ssg:generate a few times before you see the issue, but it happens. It may be the order, like if site two's home gets generated first.

@jasonvarga
Copy link
Member

Closing this as it's been sitting a while, and needs changes applied in order to work properly. If you'd like to make the requested changes we can reopen it. Thanks!

@jasonvarga jasonvarga closed this Jul 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Per-site views failing to be considered when using SSG
2 participants