The theme I’m working with shows a post date on single pages and single posts; it uses /_default/list.html and /_default/single.html. I don’t need the date on single pages. Is it possible to do a conditional in single.html that selects if a single post or single page is being rendered? Something like:
{{ if $.IsPage }} “Page, don’t show date” {{ else }} “Show date” {{ end }}
Or should I use a separate page template for single pages? If so, how would I do that?
Hi there,
What do you mean by “single post” vs “single page”?
In Hugo, “single” is usually in reference to whether a page is a “single” or regular content page, and not a list page. [doc]
If what you mean to say is that you have content/posts/lorem.md
and content/pages/ipsum.md
, then generally, lorem.md
and ipsum.md
would both be considered single Pages, and as such would both use the _default/single.html
template.
However, lorem.md
would be a "posts"
.Type
(and "posts"
.Section
) in contrast with ipsum.md
which would be a "pages"
.Type
(and "pages"
.Section
).
So you probably have to do something like
{{ if eq "pages" .Section }}
...
{{ else }}
...
{{ end }}
I am only guessing as to what you actually mean though. It would probably be easier if you shared your site code so we know we are talking about the same thing. Have a read here about Requesting Help .
Thanks, that’s what I’m trying to do. My directory structure is

and when I use
{{ if eq “pages” .Section }}
page
{{ else }}
post
{{ end }}
on single.html, “post” is output on posts, like test-post.md
; but on pages, like about.md
, I don’t see “page”.
Do I need an _index.md
in the pages directory?
pages/about/
should have .Section
value of pages
. Try printing {{ .Section }}
, what value does it give?
What version of Hugo are you using? Do you have your code somewhere we can have a look at?
Thanks! I must have been doing something wrong, as this works now in single.html
:
{{ if eq “pages” .Section }}
page
{{ else }}
post
{{ end }}