How can I conditonally show the "Summary"?

I’m building my theme from scratch. On some pages like blog posts, I want to show a summary. On some pages like projects and contact, I don’t want a summary because it makes no sense.

My front matter:

---
title: 'Projects'
date: 2024-02-24
lastmod: 2024-02-24
draft: true
tags: [ ]
summary: ""
---

The relevant part of single.html:

{{if not (eq .Summary "")}}
<p> {{ .Summary }}</p>
{{end}}

I know I can use ne, but this reads better for me

For the front matter above, shouldn’t the if statement be false? Rather, if summary is left empty, it instead uses the first few words of the remaining markdown. If I set summary to be empty, I don’t want it to show, at all.

From this page as well: Content summaries | Hugo, it seems hugo ALWAYS needs a summary, and it automatically gets one if it can’t find one

How can I get around this? I can replace "" with " " and just check for " " instead but that just seems hacky. Is that my only option?

Thanks

Posts, projects, and contact are three different content types. Conditionally display the summary based on content type.

See https://gohugo.io/methods/page/type/.

1 Like

Thank you so much for that! I don’t know how I didn’t find it sooner. Hugo makes more sense now.

Most of the tutorials/articles I saw just kept everything in the _defaults folder without any extra info so I just assumed everything goes there.

My project is now well structured properly (I hope)

I’m deleting the _defaults folder and explicitly specifying which type/layout to use in the archetypes