Gatsby: [1.0] Can you set the layout component when creating pages?

Created on 7 Jun 2017  ·  3Comments  ·  Source: gatsbyjs/gatsby

Is this planned or somehow already possible?

question or discussion

Most helpful comment

Its possible via the onCreatePage page api in a gatsby-node file something like:

exports.onCreatePage = ({ page }) => {
  if (page.path.startsWith('/getting-started')) {
    page.layout = 'getting-started';
  } else if (page.path.startsWith('/components')) {
    page.layout = 'components';
  }
};

where layout corresponds to a component file in src/layouts

All 3 comments

Its possible via the onCreatePage page api in a gatsby-node file something like:

exports.onCreatePage = ({ page }) => {
  if (page.path.startsWith('/getting-started')) {
    page.layout = 'getting-started';
  } else if (page.path.startsWith('/components')) {
    page.layout = 'components';
  }
};

where layout corresponds to a component file in src/layouts

Yes, that's intended to work... although while doing the RRv4 upgrade, I dropped support for multiple layouts due to the complexity of getting things to work period. I'm finishing a refactor to this part of the code this morning which simplifies things a ton and should make it far easier to support:

  1. multiple layouts
  2. adding queries to layouts
  3. hierarchical layouts

Amazing, thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

theduke picture theduke  ·  3Comments

3CordGuy picture 3CordGuy  ·  3Comments

KyleAMathews picture KyleAMathews  ·  3Comments

mikestopcontinues picture mikestopcontinues  ·  3Comments

benstr picture benstr  ·  3Comments