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

Let user shadow "ghost" page templates #24

Open
raae opened this issue Jul 24, 2019 · 2 comments
Open

Let user shadow "ghost" page templates #24

raae opened this issue Jul 24, 2019 · 2 comments
Assignees
Labels
invalid This doesn't seem right

Comments

@raae
Copy link
Collaborator

raae commented Jul 24, 2019

They could, of course, shadow the page template and then use a conditional to choose if they are on a specific page and if so use another component.

However, it would be nice if they could simply create a page template named page-<filename> or page-<index>.

This is similar to the page hierarchy in WordPress.

@raae raae self-assigned this Jul 24, 2019
@raae
Copy link
Collaborator Author

raae commented Jul 26, 2019

This is possible

// Template hierarchy function
const resolveTemplate = (...paths) => {
  const requireTemplate = path => {
    try {
      return require.resolve(path)
    } catch (error) {
      return false
    }
  }

  for (const path of paths) {
    const template = requireTemplate(path)
    if (template) {
      return template
    }
  }

  throw new Error("No valid template paths", paths)
}

// In create page
const template = resolveTemplate(
  `./src/templates/page-name-${node.name}.js`,
  `./src/templates/page-number-${index}.js`,
  `./src/templates/page.js`
)

@raae raae added this to the theme-jam-deadline milestone Jul 30, 2019
@raae raae changed the title Research: Is it possible to let users of the theme customize one specific page in the book Let user shadow "ghost" page templates Jul 30, 2019
@raae
Copy link
Collaborator Author

raae commented Jul 31, 2019

It is not possible. If the file is not in the theme it is not allowed to be overwritten.

@raae raae added invalid This doesn't seem right and removed theme-jam-deadline labels Jul 31, 2019
@raae raae removed this from the theme-jam-deadline milestone Jul 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

1 participant