How to add page-template and make Hugo understand?

Hi! I’m currently adjusting a theme (Pure) and wondered how do I make Hugo understand to use one template for a page and another for a post.

The theme currently uses _default/single.html for both “pages” and “posts”. I have created _post/single.html for posts, but how to I make Hugo understand when to use which template?

Any help appreciated!

1 Like

ha… in the meanwhile I “solved” the issue by editing tweaking the “Simple Theme”. Still for future references, I would like to know how to do this if someone does now.

I think this is a bug. I was just reviewing the code and we don’t explicitly put a “type” for pages. Seems like it should be “type: page”. If any Hugo experts have a reason why I shouldn’t make that change, lemme know.

Thanks for your reply Manton. I think I expressed myself a little unclear.

My question is what do I have to in order to get _post/single.html to work for posts and _default/single.html to work with pages as for example the “Simple” theme does. The “Pure” one seems to use only one template, the default/single.html for both, posts and page.

I have looked through the code of the “Simple-Theme” and can’t seem to find the magic responsible for that :rofl:

I think making a type for pages could work, but for some reason feels off to me. The way that I’ve handled this in my own custom theme is by making a page for content/{{my_page_name}}.md

In the front matter of that page, I have:

---
title: {{ title }}
description: {{ description }}
type: {{my_custom_type}}
---

Of course, those are all filled in with the page I want. Then I can have a template in:

layouts/{{my_type}}/single.html and know that’s the layout that will be used for that specific page.

Setting the default for pages on micro.blog to a type and then adding layouts/{{that_type}}/single.html would at least allow you to specify a different layout for pages (since the lookup order will hit that before post/single.html or _default/single.html but I think that calling it page is too confusing since technically posts are .Kind eq "page" in Hugo.

That’s a long way of saying:

  1. Here’s how I get a custom layout for a page.
  2. I don’t like the idea of using the word page for the default type, but do like the idea of assigning a type to pages by default to make it easier to address them all at once with a different template.

@jsonbecker Any other suggestions for a “type” name? Internally to Micro.blog, pages are sometimes called “menus”, but I don’t really like that either.

What about “routes”? Is that my developer brain kicking in? Generic names are hard.

I was just dealing with this but tried to fix it by messing with CSS J. Gregory McVerry - Getting Started with CMMC

When I think page I think blank slate. I don’t know enough about Hugo just enough about what I wanna do.

How about Section as page in which case we needn’t add it to frontmatter either? Type has to be added to the frontmatter. Plus Type is by default same as section, so we can also query for Type.

That said, everything in Hugo is a page, including blog posts and single pages. So, introducing a default page section will unnecessarily complicate the themes?

I think page is a good choice, which aligns with the IndieWeb naming and the distinction between pages and posts.

1 Like

Yeah, I think I need to go with “type: page” for this. That will match the UI and also the Micropub API “channels”, which are “posts” and “pages”. It’s true that Hugo kind of calls everything a “page” already, but this seems the most consistent with other parts of Micro.blog.

2 Likes

Was this resolved? And how would I go about implementing this? I’m not keen on my pages showing the published date like posts do (example), but I’m not sure how to separate them out. Do I duplicate the single template and change the type somewhere/somehow?