Skip to content

Is it possible to set a layout for a directory (and it's subdirs)? #1393

Answered by nozomuikuta
nobkd asked this question in Q&A
Discussion options

You must be logged in to vote

You could define a function on content:file:afterParse hook to set layout property to files based on their path like below:

// server/plugins/content.ts

export default defineNitroPlugin((nitroApp) => {
  nitroApp.hooks.hook('content:file:afterParse', (file) => {
    if (file._id.endsWith('.md')) {
      // some logic to detect file's path
      file.layout = layoutForDir || file.layout
    }
  })
})
// nuxt.config.ts

export default defineNuxtConfig({
  nitro: {
    plugins: ['~/server/plugins/content.ts']
  }
})

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@nobkd
Comment options

Answer selected by nobkd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants