Is it possible to set a layout for a directory (and it's subdirs)? #1393
-
I wanted to set layouts per directory (and therefore also the subdirectories), without putting it into the frontmatter of every file. Ideas i had how it could work, if it's not already possible:
Frontmatter layouts should always override directory layouts |
Beta Was this translation helpful? Give feedback.
Answered by
nozomuikuta
Jul 29, 2022
Replies: 1 comment 1 reply
-
You could define a function on // 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']
}
}) |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
nobkd
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You could define a function on
content:file:afterParse
hook to setlayout
property to files based on their path like below: