HUGO

How to set 404 Page's Params

Hugo Docs’ page for 404 template states that:

404 pages will have all the regular page variables available to use in the templates.

However, I was unable to set .Params through front-matter with content/404.md as usual.

I see there was a similar post in 2018 and a GitHub issue created by @onedrawingperday for this. But it was closed due to inactivity.

Replies to the mentioned post include some workarounds. But has the issue been resolved in the past 3 years? And if not, what is the “right way” to do this?

PS: Passing params include changing .Title of the 404 page and such. By default, 404 Page not found is passed by Hugo.

Thanks in advance!

Was just playing around…and found that .Kind for the 404 page is literally 404. Is it the correct way to detect a 404 page? And should it be used to write the template logic if setting .Params is not possible?

I use this, for example : {{ if eq .Page.Kind "404" }}

1 Like

@divinerites Yeah. But I was wondering if that is actually the “hugo way” of doing it. Since docs say otherwise.

The built-in 404 functionality is limited and specific to a single error page (404). In my view this is a better approach:

content
└── errors/
    ├── 400.md
    ├── 401.md
    ├── 403.md
    ├── 404.md
    └── _index.md
layouts
└── errors/
    └── single.html

content/errors/_index.md

[_build]
  list = 'never'
  render = 'never'
[cascade._build]
  list = 'never'

Just make sure to reconfigure the error page paths on your production server.

errors/400/index.html
errors/401/index.html
errors/403/index.html
errors/404/index.html

See related discussion:
https://github.com/gohugoio/hugo/issues/8924

1 Like

@jmooring Thanks for this. I think this tidbit along with adding some examples (or at least links to) server configs (and services like Netlify; I know you can do this on Netlify, but it’s not immediately obvious for new users, and I forget the steps involved although I can figure them out) in the docs would probably be helpful as well. I’ll add that my to do list, but it’s not a high priority item for me, so hopefully someone beats me to it.