Setting layout in Front Matter
See original GitHub issueIt’s possible to set the layout inside the front matter of markdown files? Like this:
content/blog/hello-world.md
---
layout: 'layout-1'
title: Hello World
---
content/blog/featured-article.md
---
layout: 'featured-layout'
title: Article with special layout
---
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Front Matter - Hugo
Front matter allows you to keep metadata attached to an instance of a content type—i.e., embedded inside a content file—and is one of...
Read more >Front Matter | Jekyll • Simple, blog-aware, static sites
If set, this specifies the layout file to use. Use the layout file name without the file extension. Layout files must be placed...
Read more >Front Matter | Hugo - Mike Dane
This tutorial covers how to use front matter in Hugo - Static Site Generator. ... we can use elsewhere (like in layouts) to...
Read more >Hugo change layout - Stack Overflow
Use front matter to set the "layout": In content/get-started.md set layout: mylayout in front matter. The layout will be located at (for ...
Read more >Front-matter | Hexo
The default layout is post , in accordance to the value of default_layout setting in _config.yml . When the layout is disabled (...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I also dug into this issue and here are what I found.
Firstly, as @mrhubbs pointed out,
layout
option must be either a string or a synchronous function that returns a string. Fetching the document is asynchronous, so modifyinglayout
option can not be an option to achieve the goal.Another way is, as described in this issue, to modify
context
inmiddleware
function which is called beforelayout
function.I tried this approach and it seems working.
I set
document
as well asdocumentLayout
just because I thought fetching document twice inmiddleware
andasyncData
would be at higher cost.Note that I just did a quick testing in my local:
yarn create nuxt-content-docs test-layout
.yarn link
to replace installedcontent-theme-docs
package with that in my local.layout: single
in the front matter ofsetup.md
file.yarn run dev
, and check whether layout is changed dynamically when I move betweenindex
andsetup
pages.yarn run generate
,yarn run start
, and check whether layout is changed dynamically when I move between the 2 pages.Using document-driven mode in nuxt/content@v2 you can set layout name in front-matter.
I’m closing this because nuxt/content@v1 will not receive any update for this.