Customizing Pages/Understanding how Pages work on Micro.blog

I’m trying to better understand how to customize the content for my Pages on micro.blog. I want to customize a reading page using the data available in the new bookshelves feature.

I’ve tried putting a template in:

layouts/posts/reading.html.html or layouts/posts/reading/single.html but I don’t think the content is picked up in either one. I’ve also tried using a trick I’ve used before, with {{ if (eq .Title "Reading") }} in my layouts/posts/single.html but that also doesn’t seem to get picked up/triggered on the page generated by creating a new page at myurl.com/reading (even though it appears to me that Reading is the page title).

Is there any front matter I can use to determine if I’m on this page? What template does it draw from and is there a way to target that template?

In stock Hugo, I suspect I’d either make this a type (not post) or have this as reading.md not under posts and use a layout like layouts/reading.html that I think would pick that up (and that md file would probably be just front matter).

Pages on Micro.blog have always thrown me off a bit because they seem like posts with custom permalink URLs, but they have been a bit hard to target with anything other than standard post markdown content to be processed by layouts/posts/single.html.

2 Likes

I would like an answer to this, too.

EDIT: Just to add a little bit of extra info: The info provided here about a custom 404 page seems to suggest that if you have a page with the slug /test then a template /layouts/test.html should be applied. Sadly this is not the case for me.

1 Like

Yeah, this is confusing and I think Micro.blog needs some tweaks to make standalone pages work better, like extra post types. I think for now what you want to do is create a file in the theme in the “content” folder, like content/reading.md and then specify the layout in the front matter?

I’ll do some more testing on this. Thanks!

3 Likes

Doesn’t seem to be working:

I have a page called Titles (slug /titles), which is supposed to only show posts that have a title. It looks like this:

I then created a custom template called content/titles.html it has this (test) content:

{{ define "main" }}
<div class="home h-feed">

  <ul class="post-list">
	{{ $paginator := .Paginate (where .Data.Pages.ByDate.Reverse "Type" "post") (index .Site.Params "archive-paginate" | default 25) }}
	{{ range $paginator.Pages  }}
		{{ if .Title }}
      <li class="h-entry">

			<h1><a href="{{ .Permalink }}">{{ .Title }}</a></h1>


        <a href="{{ .Permalink }}" class="u-url"><span class="post-meta"><time class="dt-published" datetime="{{ .Date.Format "2006-01-02 15:04:05 -0700" }}">{{ .Date.Format "Jan 2, 2006" }}</time></span></a>

        <div class="e-content">
         	{{ .Content }}
        </div>
      </li>
		{{ end }}
    {{ end }}
  </ul>

  <p class="rss-subscribe">subscribe <a href="{{ "feed.xml" | absURL }}">via RSS</a></p>

</div>
{{ end }}

I also tried to put a different string into the front matter: content/titles.html, titles, titles.html but none work for me.

What am I doing wrong?

@manton I still would like to know. I have plans to customize my blog, but I am blocked by not knowing/understanding how pages work. I think I grok Hugo’s templating enough. I just don’t know how to apply a custom template to a page. It’s quite frustrating that I can’t seem to figure it out.

1 Like

Thank you so much for your helpful post! I tried it out and it seems to work, sadly for my use case, namely having another list-page for a filtered down list of my blog’s content, I couldn’t get it to work.

1 Like