Custom 404 page with content from md file #809
Replies: 3 comments
-
GoHugo does not support a content file for 404 errors (it's not planned to my knowledge). What you can do is something called a "headless page" for your content (option 3) or (what you already started) add the content to your custom 404 template (either directly or via one of these three options):
The first one is the easiest, the last one the most work. But the last one puts your content into the content directory, if you do anything else with it (like linting). |
Beta Was this translation helpful? Give feedback.
-
In general: The page you created is available at See this page for a list of common server configs. |
Beta Was this translation helpful? Give feedback.
-
thank you for a prompt response @davidsneighbour.
I think this will not be possible in my setup, as I host it on github pages, and "Redirection to is automatic and not configurable". However your first suggestion works well. I am able to connect the content of a file stored in - title: "PY20555STI"
featured_image: "/images/home.jpg"
Content: "This is content" with the layout and render it correctly using the custom layout in {{ define "header" }}{{ partial "page-header.html" . }}{{ end }}
{{ define "main" }}
<article class="center cf pv5 measure-wide-l">
<h1>
{{ range $category, $404data := .Site.Data.files }}
<p>{{ $category | title }}</p>
{{ range $404data }}
title: {{ .title }}
</br>
featured_image: {{ .featured_image }}
{{ $featured_image := .featured_image }}
</br>
Content: {{ .Content }}
{{ end }}
{{ end }}
</h1>
</article>
{{ end }} The missing link is how to use the value of So far the site renders as: Interestingly, the removal of |
Beta Was this translation helpful? Give feedback.
-
I use ananke through module import and set it as my theme, which works great.
I wanted to be able to customise the 404 page, so I've created a
content/404.md
file, that contains:but that results in a "Page Not Found" error (not the default 404 page):
This is surprising, as I can see that the custom 404 page was created in
public/404/index.html
and contains the information from the md file:Furthermore, I am able to override the default 404 page, by placing a custom file in
layouts/404.html
, but if I try to include the content of md file in that custom 404, the same "Page Not Found" error happens.Beta Was this translation helpful? Give feedback.
All reactions