If you have received this post by email, please ignore it. It’s a test and I intend to try to delete the email before the it is sent out. If I haven’t managed to do that, my apologies.

I’m using one of the three newsletter options available on Micro.blog: any post with a title is sent to email subscribers. Because I want the title of the post to appear in the body of the email as a heading, I include that heading at the start of the post.

However, there are posts with titles that I wrote before the newsletter option was available. Those posts don’t include the title in their body because, at the time, I relied on the relevant Hugo template to insert the title as a heading.

So, now, I want the template to include the title-heading in posts which have a title but do not belong to the newsletter (like this one). On the other hand, I want to omit the title-heading when the post is part of the newsletter. Clear? Didn’t think so.

I’ve done what I wanted by adding the following to the relevant template, layouts/post/single.html:


{{ if and .Title (not (in .Params.categories "Newsletter" )) }}
    <h1>{{ .Title }}</h1>
{{ end }}

What that means is that the Title is included in the body of the post if both of the following conditions are true:
  1. The post has a title; and
  2. The post does not belong to the “Newsletter” category.

In other words, it’s an example of how to combine AND and NOT.