I feel like I might be missing something basic because I have what I think is a common use case that I’m not sure how to solve.
Imagine having a “blog” content type of which you have a “blog” layout. Everything is good so far but now you have a type of blog post called a “tip”. Tips have the same exact layout and URL paths as a regular blog post, the only difference is a few frontmatter properties which in turn render certain elements differently (a different newsletter or blog hero image, etc.).
In Jekyll this was really easy, I made a tip layout which derived from layout: "blog"
and then I set my custom frontmatter there since Jekyll lets you set frontmatter in a layout. Then in every tip blog post I set layout: "tip"
and everything worked.
In Hugo I don’t know how to solve this. You can’t seem to set frontmatter in layouts and while archetypes exist, they seem coupled to the file system since you can’t set archetype: "tip"
in a post’s frontmatter to select a different one. I don’t want a content/tip
directory since in my mind a tip belongs in content/blog
since it’s effectively a type of blog post.
How do you handle this use case where you have 1 content type that needs to be slightly customized with frontmatter?
I have over 100 tips and want to avoid explicitly setting the common tip related frontmatter properties in each one. I also want to avoid adding a bunch of custom tip related logic in my base layout with conditions around checking if it’s a tip based on the file name of the post, etc…