How do I force a certain page to user certain single.html file? I need a Contact page to use a particular single.html that contains a form. I don’t want other pages or posts to use that single.html. I’m using 0.65.
My Contact page at /pages/contact.md contains:
+++
title = “Contact”
description = “Contact”
+++
Contact Me
And I want contact.md to use /layouts/contact/single.html which contains
layouts/contact/single.html loads the single template for the “contact” section. I think you want something at layouts/_default/contact.html, and then set layout to “contact” in front matter.
Thanks, we’re geting closer. In contact.md, I now have
+++
title = “Contact”
description = “Contact”
layout = “contact”
type = “contact”
+++
Contact
and now when I go to root/pages/contact/, that uses layouts/contact/contact.html I get a partially rendered page. I have to delete {{ define "main" }} and {{ end }} from contact.html and then I get the rest of the html output that is between the <article> tag and the ending </div>. So the {{ .Content }} and {{ .Title }} tags render OK. But in this case, something is wrong with the {{ define "main" }} tag.
Anyone have an idea of why I have to delete {{ define "main" }} and {{ end }} from contact.html to get the html output that is between the <article> tag and the ending </div> ?
You have closing </div> tag floating outside of any defining blocks. The templating language isn’t defined for that happening I think? I remember reading somewhere that it’s not a great idea. Try making sure all html and whatnot are within {{ define "block" . }} <div> hello </div> {{ end }} blocks.
Thanks, but using a define "block" in contact.html throws an error when starting Hugo. If you want to take a look, I added a repo of the entire theme: https://github.com/mtbluedog/hugo_theme
Thanks, that’s really strange; still doesn’t work for me. draft=false doesn’t make a difference.
But as soon as I use layout = "contact" in contact.md, contact.html (in layouts/_default/) won’t render anything, unless I remove the {{ define "main" }} and {{ end }} , and then I get the rest of the html, and also the output of {{ .Content }} and {{ .Title }}. So for some reason, {{ define "main" }} and {{ end }} are breaking.
I tried the same thing with a different page, too; same result. This is with the newest Hugo.
your contact.html layout page has the closing </div> outside the define block. This is breaking your template. See doc: Base templates and blocks | Hugo
Ah, you’re right. Fixed that, now it works. That was the way the base theme I’m using was coded; I don’t know why it was working before with the div outside.