[SOLVED] Problems rendering a Contact Page partial and using Layout

Sorry to revive this old chestnut but I’m still confused. I have a page in the root of my content folder along with other static pages - this page is called content/contact.md and the front matter is as follows…

title = "Contact"
date = 2018-03-13T09:44:54Z
draft =  false
type = "page"
layout = "contactlayout.html"

I placed a layout for this in layouts/page/contactlayout.html

{{ partial "header.html" . }}
<div class="container">
  <h2>{{ .Title }}</h2>
  {{ .Content }}
  {{ partial ".contactform.html" . }}
{{ partial "footer.html" . }}

However the contact.md is still rendering using _default/single like all the other pages.

I must be doing something REALLY stupid but I just can’t see it. If somebody could point out what it is I’d be grateful


Try specifying without the .html?


Thanks - just tried it and it didn’t seem to work.


I think that the template path should be layouts/page/single.html


Okay I tried that and the page 404d.


Do you have a link to your repo?



I just tested making a layout, and specifying it in frontmatter, and it worked no problem. Here’s what I did:

  • copied /layouts/_defaults/single.html to /layouts/post/testing.html.
  • changed /layouts/post/testing.html a little so I could tell the difference.
  • edited a post in /content/post/, and specified the layout in its frontmatter as layout = "testing".
  • saved, and hugo server shows the file has picked up the proper testing.html layout.
  • changed to another post, and could see that it still has the regular default single as its layout.

So, it does work.


My content isn’t in /content/post its in content/

I have other folders content/rides content/news content/reports and these all work as expected.


(remove confusion causing untested suggestion)


I tried changing the type to “other” and it still did not work.

Really confused


OK, thanks for trying and sorry for the confusion. I suggested that just based on a theory.

I will try your repo once I get to a PC. But one thing is for sure: Do not use the .html extension when specifying the layout in the front-matter.

I haven’t tried your exact example, but I have this in my tests and it works, and here’s the layouts dir for the test site.

Do you want to try out the exact same example in the meanwhile someone else or me figures out what’s wrong with your setup?

Your site has multiple problems unrelated to what you think is wrong.

First of all in your contact.html you call a partial with your contact form like this:
{{ partial ".contactform.html" . }}

Then within that partial you have {{ .Content }} -that you shouldn’t- and you have the contact form wrapped within a {{ if isset .Site.Params "email" }} and that parameter is missing from your site config.

@mshiner @kaushalmodi @RickCogley I have moved the posts from the other thread to this one. To continue this discussion in a more appropriate topic.

PS Just figured out how to move posts into a new thread. Apologies for closing the other thread but it was getting OT.

1 Like

Ok. To render the form in your contact page you need to do the following.

In your config.toml include the following parameter

email = "some@gmail.com"

Then in the front matter of contact.md change your layout parameter to:

layout = "contactlayout"

In your template located at /layouts/page/contactlayout.html delete the first dot from your partial like so:{{ partial "contactform.html" . }}

Then within your contactform.html partial remove {{ .Content }} you already have it in your template above and including it a second time causes Hugo to choke.

Also {{ if isset .Site.Params "email" }} does the same as {{ with .Site.Params.email }} but the latter is terser and preferable.

With the above changes your contact page will render as you intended.

I thought that would just cause the .Content to show up twice…

Thanks for all the ground work (not yet at a PC).

@mshiner, ok, just tried it on my site, moving /layouts/post/testing.html to /layouts/_default/testing.html, then adding a /content/testpage.md. When I set the frontmatter of testpage.md to include layout = "testing" as in the example above, it still works. The page http://mysite.com/testpage/ picks up the layout.

(the other more practical problems being pointed out, notwithstanding)


Works now - I had screwed up completely but Alexandros has sorted me out.

That’s the problem with being a noob ;-D



Of course, not a problem. Didn’t check for this exact case on this page:

… but, this explains pretty well what Hugo is looking for, in what order.

It takes a while to get your head around it, and processing all the docs is a slog at first, but, once you grok it, it’s super powerful and interesting (in my opinion).