Setting a custom single layout for nested section

With content/posts/news/, I want the single pages in news to share a custom single layout without needing to include the layout in every page. The workaround was using a partial and a conditional statement, but I would prefer to stick the layout in the default folder for future re-use.

layouts/
└── _default/
    β”œβ”€β”€ baseof.html
    β”œβ”€β”€ foo.html    <-------
    β”œβ”€β”€ list.html
    └── single.html

content/posts/news/news-1.md

+++
title = 'News 1'
date = 2022-12-03T15:27:26-08:00
draft = false
layout = 'foo'
+++

I guess I will just stick to partials and conditional statements then since I am avoiding the solution you shared. Nested sections support is tricky!

I misunderstood your request.

layouts/
└── _default/
    β”œβ”€β”€ baseof.html
    β”œβ”€β”€ foo.html    <-------
    β”œβ”€β”€ list.html
    └── single.html

content/posts/news/_index.md

+++
title = 'News'
date = 2022-12-03T15:46:30-08:00
draft = false
[[cascade]]
layout = 'foo'
+++

I tried cascade before posting the question but the pages are blank. A quick look and it was a - placed in the Go comments block {{- /* */}} that made the page blank. Such a minor mistake!

That’s a valid comment:

{{- /* Something */}}
1 Like

In my local server it returns the β€œwhite page of death” (now it picks the 404 page). But It disappears when I close the comment with another -. I placed it before {{ define "main" }}.

{{- /* Something */ -}}

Then you have a different problem.

Just figured I did not specify placement. I edited my previous comment.

OK, that’s a bug.

You can do this:

{{/* Foo */}}
{{ define "main" }}

but not this:

{{- /* Foo */}}
{{ define "main" }}

Is that Hugo Specific or Go specific bug?

Specific to Hugo:

https://github.com/gohugoio/hugo/blob/master/tpl/tplimpl/template.go#L91

Noted! I am not on Github otherwise I would have raised it.

I’ll create an issue. It’s an easy fix.

Amazing!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.