Accessing layout value in front matter

I’ve had a great deal of good luck with Hugo and things are going well. However, I have a new need and it’s vexing me a bit. I suspect that there’s a very (very!) easy way to do this but it is not at all clear to me. I appreciate any help.

In list.html, I restrict the list function to certain categories and types:

(or (eq .Section "post") 
  (eq .Section "needhelp") 
  (eq .Section "buildingbetter") 
  (eq .Section "anxiety") 
  (eq .Section "stress") 
  (eq .Section "depression") 
  (eq .Section "mentalhealth") 
  (eq .Section "news") 
  (eq .Section "authors") 
  (eq .Section "categories") 
  (eq .Section "tags") 
  (eq .Section "topics")
)

What I’m trying to do now is to omit posts that have a layout type of “home”. Hugo actually excepts this format but it doesn’t exclude the posts I want to omit. Here’s a sample post that should be omitted:

HOME.MD:

---
title: "Authors Home"
date: 2020-01-05T11:07:10+06:00
description: "Articles and news related to the site authors."
draft: false
image_name: "taxonomy"
description: "this is meta description"
draft: false
layout: "home"
---

And here’s the logic from list.html that does not work:

{{ define "main" }}

{{ if or (eq .Section "categories") (eq .Section "tags") (eq .Section "topics") }}
  {{ partial "taxonomy-page-title.html" . }}
{{ else -}}
  {{ partial "page-title.html" . }}
{{- end }}

<!-- checking blog -->
{{ if 
  (and 
    (or (eq .Section "post") 
       (eq .Section "needhelp") 
       (eq .Section "buildingbetter") 
       (eq .Section "anxiety") 
       (eq .Section "stress") 
       (eq .Section "depression") 
       (eq .Section "mentalhealth") 
       (eq .Section "news") 
       (eq .Section "authors") 
       (eq .Section "categories") 
       (eq .Section "tags") 
       (eq .Section "topics")
    )
    (ne .Params.Layout "home")
  ) 
}}

… followed by the rest of the list html, which works just fine.

Thanks for any assistance.
Brian

Are you trying to include:

  1. Pages in those sections without layout “home”
  2. Pages in those sections AND pages without layout “home”

Hi Joe!

What I was trying to do was to include only pages in those sections without the layout “home”.

I was trying to omit what we call Home pages(they are essentially section headers) from showing up in lists. I was able to solve the problem another way by removing the category item from the front matter for those pages when I realized that they didn’t need that entry at all.

Thanks,
Brian

Then your conditional is fine. Not sure where the problem was, but it sounds like this is no longer relevant.

I’m not sure either but I think my error was related to trying to access the “Layout” front matter.

Thanks for offering to help!
Brian

No, I tested that and it worked as expected.

Thanks, Joe. That’s good feedback.

One of these days, I’m going to bite the bullet and just go learn Go. Hugo is so sensibly designed that I haven’t needed to do that yet and the site we’re working on looks great so far. But one of these days, I really need to do that.

At my age and with 26 programming languages in the past, I’m not enthusiastic about adding a 27th but I think I really need to do that, at least so I don’t post stupid questions here. :slight_smile: