Custom template file for specific single page?

I’m trying to create a theme template for a specific page. I have a single page stored in content/contact.md and I would like to create a theme template for this page only as the design is different to other single pages.

I’ve followed the docs: https://gohugo.io/templates/lookup-order/ and attempted to place the following files. None work:

  • theme/mytheme/layouts/_default/contact.html
  • theme/mytheme/layouts/_default/contact.html.html
  • theme/mytheme/layouts/contact/single.html

In the template I have the following:

{{ define "main" }}
Testing, testing
{{ end }}

I’m expecting testing to be displayed, but it’s not and appears be using theme/mytheme/layouts/_default/single.html

I’ve tried adding: type: "contact" to the frontmatter but I still can’t get the contact page to use it’s own template. Any ideas?

1 Like

Nope. We don’t know what’s in your content file, or config, or if there are other templates blocking it. Please share code as suggested, and we will figure it out. :slight_smile:

Try layout: contact

2 Likes

To give a more complete answer, apparently layout: contact in he front matter AND placing the contact.html inside _defaults worked for me.

I guess this is the only valid option three years later, and without the front matter there’s no other way, right?

According to this it still should be like that Formcake - How to add a Static Page to Hugo

├─ content/
│ ├─ contact.md :clipboard:

├─ layout/
│ ├─ _defaults/
│ │ ├─ contact.html :white_check_mark: + layout: contact
│ ├─ contact/
│ │ ├─ single.html :x:
│ ├─ contact.html :x:

1 Like