Layout configuration in Front-matter (like Jekyll)

Hi All,

After a year long of using jekyll, I am finding Hugo’s speed and flexibility to be a delight. However, there’s one feature I miss from my Jekyll, which was describing custom layouts in the front matter. For example, my blog posts have a paging section (showing next and previous posts) which is something also showing in my About or Projects page. Is there a way to provide a custom layout for specific pages?

# Jekyll example
---
layout: post
title: Blogging Like a Hacker
---
# about page YAML
---
layout: single-col
title: About
---
1 Like

You can say

type: myspecialtype

And then add a template or two for that:

/layouts/myspecialtype/single.html

Have a look at section vs. type in the documentation – I know there have been some changes / fixes in that regard lately.

3 Likes

I figured I can use custom variables to achieve the same effect (almost). Thanks a lot!

type is the easiest path. Otherwise put something like

{{ if eq layout "single-col" }}
Do something
{{ else }}
Something different
{{ end }}

Or if your CSS is smart

<div {{ with .Paramus.layout }}class="{{ . }}"{{ end }}>

Or

<body {{ with .Paramus.layout }}class="{{ . }}"{{ end }}>

I was scratching my head trying to figure out why a single layout for a type wasn’t getting applied (after I saw it had been) and realized after reading @bep comment it was due to me trying to overload type in my front matter for an entirely different purpose. :sweat_smile: