Skip to content

Accessing info from a dynamic page in layouts? Configuring layouts dynamically #111

Answered by ElMassimo
mseele asked this question in Q&A
Discussion options

You must be logged in to vote

The problem with choosing a layout dynamically, is that in order to bundle the app consistently (specially CSS), it's important to resolve which page uses which layout statically at build time. Now, let's look at ways to achieve similar results.


In most cases, extendFrontmatter provides enough flexibility to set layout accordingly for each page:

  // Example: Configure all posts to use a different layout without having to
  // add `layout: 'post'` in every file.
  extendFrontmatter (frontmatter, filename) {
    if (filename.includes('/posts/'))
      frontmatter.layout ||= 'post'
  },

However, since you are referring to blog posts fetched from a CMS, you are probably using Dynamic Paths,…

Replies: 6 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by ElMassimo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #109 on March 28, 2022 19:18.