Skip to content

Commit

Permalink
docs: add section on multiple layouts to gatsby-layout-plugin docs (#…
Browse files Browse the repository at this point in the history
…9538)

Adding a section on how to use multiple layouts to gatsby-layout-plugin docs. Might be helpful to anyone trying to build a site with a more complex layout system (and who still needs to use or prefers the layout philosophy used in Gatsby v1).
  • Loading branch information
msachi authored and DSchau committed Oct 30, 2018
1 parent 43c1264 commit 6bbc4f0
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions packages/gatsby-plugin-layout/README.md
Expand Up @@ -179,3 +179,33 @@ const ComponentThatChangeState = () => (
</ContextConsumer>
)
```
### Handling multiple layouts
If you want to use different layouts for different pages, you can pass this information in the context of the pages you create, and then conditionally render in your layout file.
In `gatsby-node.js`:
```js
exports.onCreatePage = ({ page, actions }) => {
const { createPage } = actions

if(page.path.match(/special-page/) {
page.context.layout = 'special'
createPage(page)
}
}
```
And then in `src/layouts/index.js`:
```js
export default ({ children, pageContext }) => {
if (pageContext.layout === 'special') {
return <AlternativeLayout>{children}</AlternativeLayout>
}
return (
<RegularLayout>{children}</RegularLayout>
)
}
```

0 comments on commit 6bbc4f0

Please sign in to comment.