Check If a Page Is the Home Page

When writing and changing Hugo templates you will often want to act differently based on whether the page you are looking at is the home page, or any other page. So the post pages, contact, about etc won’t have this content show.

Likewise the reverse is also useful - only show something on the home page. Both of these scenarios are possible through using IF statements in your templates.

On Home Page Only

1
2
3
{{ if .IsHome }}
	this is the home page
{{ end }}

Every page except Home Page

For the reverse we have use the ne command and check it against our bool value.

1
2
3
{{ if ne .IsHome true }}
	this is the home page
{{ end }}