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

Layouts and Templates - How are they supposed to work and how do they work right now? #1469

Closed
mikestopcontinues opened this issue Jul 11, 2017 · 3 comments

Comments

@mikestopcontinues
Copy link

These two concepts seem redundant. And I've seen some issues suggesting they aren't fully sorted out in V1. Can someone clarify how they should work and how they do?

  1. Why do both layouts and template components exist?

  2. How do you select alternative layouts for content? (I saw a frontmatter field in the blog starter, but I couldn't trace it to any actual effect. In any case, this seems like the kind of thing you'd do in createPages, not a built-in frontmatter override doesn't it?)

  3. How do nested templates work? Or how should they work? Or why would you need them if you can select different template components for different pages?

Thanks!

@KyleAMathews
Copy link
Contributor

re 1) Template components are for page types e.g. blog posts, documentation pages, etc. Layout components are for everything shared across pages e.g. headers, footers, sidebars, etc. They're both needed because they're very different things :-) Read https://www.gatsbyjs.org/docs/building-with-components/ as well

re 2) you can't right now. This is something we'll support in the future. Those frontmatter fields were old and not used. Sorry about that. Just removed them. Markdown posts are created with createPage so one possible way of allowing a markdown post to override the default layout would be using frontmatter to select a layout.

re 3) also not supported yet but planned for the future. One use case is you have a global layout with a header/footer and then a sub-section of the site that has a secondary sidebar navigation.

@casprwang
Copy link
Contributor

you can take Layout as a higher order template which controls other templates and passes the global components like Nav, Footer..., and use specific templates to differentiate the contents. For example, If I created one Layout with Nav bar and Footer, and two templates named Pages and Blogs, both Pages and Blogs would take Nav bar Footer from Layouts, and have different content within.

@mikestopcontinues
Copy link
Author

Thanks, this clears things up. 😀

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

No branches or pull requests

3 participants