Custom layout not working for contact.md

Hi everyone :waving_hand:

I’m fairly new to Hugo and I’m having a bit of a hard time understanding how layouts are selected — I’ve read the docs and searched the forum but something still doesn’t add up in my case.


:wrench: The situation:

I have a simple page at:

content/contact.md

And I want it to use a custom layout. So I created:

layouts/contact/single.html

Then in the front matter, I’ve tried several combinations like:

type: "contact"
layout: "single"

or even just:

layout: "contact"

But Hugo always ends up using layouts/_default/single.html. No matter what I do, my custom layout never gets picked up.


:white_check_mark: What’s weird is… it does work elsewhere:

I have another section for legal pages:

content/pages-legales/cgu.md
content/pages-legales/cookies.md

And I use:

  • layouts/pages-legales/single.html
  • With front matter: layout: "legal"

→ This works perfectly.

So I’m confused why contact.md doesn’t behave the same way.


:red_question_mark:What I’ve tried so far:

  • Created layouts/contact/single.html → doesn’t work
  • Used layout: "contact" → doesn’t work
  • Tried layouts/_default/contact.html → still no effect
  • Explicit type: "contact" + layout: "single" → ignored

I just want Hugo to use layouts/contact/single.html for contact.md :sweat_smile:

This is a bug, a regression from 0.147.9 to 0.148.0.

See https://github.com/gohugoio/hugo/issues/13868.

For me that works - 147.9, 148.0, 148.1 - layout structure is 146+

  • content/contact.md
    +++
    title = 'Contact'
    layout = 'contact'
    +++
    
    Contact Page
    
  • layouts/contact.html
    {{ define "main" }}
       <h1>{{ .Title }}</h1>
    
       <h4>{{ templates.Current.Filename }}</h4>
       <h4>{{ warnf "%s -- %s " .Title templates.Current.Filename }}</h4>
       {{ .Content }}
    {{ end }}
    

Remove layout from front matter; this is a regression.

again lost in space here, sry:

guess you don’t tell me that having layout field in front matter is the regression

could you give me some more words on that, please.

See assertion here:
https://github.com/gohugoio/hugo/issues/13868#issue-3256732647

1 Like

ok, got the regression

hugo v0.147.9-29bdbde19c288d190e889294a862103c6efb70bf+extended windows/amd64 
WARN  Contact -- C:\_repos\github\clone\topic-55405-contactpage\layouts\contact\page.html
WARN  a Page -- C:\_repos\github\clone\topic-55405-contactpage\layouts\page.html
hugo v0.148.0-c0d9bebacc6bf42a91a74d8bb0de7bc775c8e573+extended windows/amd64 
WARN  Contact -- C:\_repos\github\clone\topic-55405-contactpage\layouts\page.html
WARN  a Page -- C:\_repos\github\clone\topic-55405-contactpage\layouts\page.html

does it also mean the layout = 'mylayout' and layouts/maylayout.html should not be used?

The layout field trumps all.

1 Like

Thank you all for your suggestions and support.

Just to update: I’ve tried all the recommended solutions, including :
– Creating a layouts/contact.html and using layout: "contact" in the front matter
– Creating a “fake section” with content/contact/_index.md and using layouts/contact/single.html
– Cleaning the cache and restarting Hugo

Unfortunately, nothing works for my orphan page (/contact/), even with a fresh structure and no drafts. Oddly, the exact same approach does work for my “legal pages” section (/pages-legales/), which just adds to the confusion.

At this stage, it really looks like Hugo is broken for orphan pages and custom layouts in v0.148+.
I will try downgrading to 0.147.9 to recover a stable and predictable behavior.

Thanks again for your help—hopefully this will get fixed in a future release.

pretty sure that will be fixed :wink:

reading back, you mentioned layouts/_default so maybe you have not everything migrated to the new layout structure.

dunno if that may affect something here, but the bare setup using frontmatter layout works for a workaround/override

try it out here

git clone --single-branch -b topic-55405-contactpage https://github.com/irkode/hugo-forum.git topic-55405-contactpage
cd topic-55405-contactpage
hugo server
1 Like

just tested with v0.148.2 and it works like a charm

\LAYOUTS
│   baseof.html
│   home.html
│   page.html
│
└───contact
        page.html

\CONTENT
    contact.md
    some-page.md
    _index.md
hugo v0.148.2-40c3d8233d4b123eff74725e5766fc6272f0a84d+extended windows/amd64 BuildDate=2025-07-27T12:43:24Z VendorInfo=gohugoio

WARN  Contact -- C:\_repos\github\clone\topic-55405-contactpage\layouts\contact\page.html
WARN  a Page -- C:\_repos\github\clone\topic-55405-contactpage\layouts\page.html
WARN  Home -- C:\_repos\github\clone\topic-55405-contactpage\layouts\home.html

@alexispart : maybe do a retest yourself and mark as solved