HUGO

Use custom single page template

I have a problem to trigger a custom single page on my posts. The content is organised like this :

enter image description here With all my posts into the posts folders (I’m no using an _index.md because this folder is one step behind the /content and is considered as a Section for Hugo)

And my layouts look like this (i’m not using a theme) :

enter image description here

However when i click of one of my post leading to /posts/name-of-post/ URL it renders the layout/default/single.html template. I’m really questioning myself since i saw the Hugo’s Lookup Order saying that layout/default/single.html has a lower priority than the layout/section/single.html. Moreover when i delete the default/single.html i got an error saying that no “type” “Page” is implemented. Consequently i’m assuming i’m mistaken on the architecture. Then i saw this page of the official documentation using the exact same architecture than mine. I need your help to figure out what’s wrong in my folder and i can give further details if needed. Thanks in advance.

We need to see the context of your templates and content files.

So it would speed up things if you could share the source code of your project through GitHub or another Git provider or if you are not using git then share a ZIP containing the project folder.

Thanks for your reply and I understand you want more informations. Here is a really simple project where the problem occured : https://sendeyo.com/show/bb374d61e9. To be honnest, i solved the problem sniffing in the support question : i added “type: posts” in my post and the posts/single.html was trigered. But this method don’t really make me happy because i have hundreds of posts i imported from wordpress and none of them got this taximony. Is there another mean to do the pointing from the content to the single rendering template ?

Actually, i just figured out than if i add type: posts in a _index.md into the content/posts folder it works.

In the folder you shared the file under:

content/posts/2020-09-25-watch-the-fastest-typists-share-their-typing-tips-tricks.md

has type post in its front matter.

To make it to pick up the template under /layouts/posts/single.html you need to remove the type parameter from its front matter.

Please note that the plural form defines different post types in Hugo. i.e. posts is not the same post and that’s why the /layouts/_default/single.html template is currently used.

For content files under /content/posts/ you do not need to add a type parameter and the template that will be used automatically will be the one under /layouts/posts/single.html

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.