Is it possible to limit a range to the standard layouts?

When needed, I use a range statement like below to exclude content that is under the same content folder but uses a custom layout.

{{range where .Pages "Layout" "not in" (slice "a" "b" "c" "d")}}

Instead of listing all the content to exclude either by Type or Layout, I figured out that can I range through content that has no specified layout by doing:

{{range where .Pages "Layout" "" ""}}

Is there a better way of doing this to make the code more understandable?

use html comments in your files to comment the code!

<!-- comment this code -->

Hugo will NOT copy the comments to the generated sites.

@ju52 No, Hugo strips out HTML comments. So you have to print them instead. (As seen below only the 3rd line is printed).

For example, this code:

<!-- (1) do you see me? -->
{{/* (2) do you see me? */}}
{{ print "<!-- (3) do you see me? -->" | safeHTML }}

Gives:

<!-- (3) do you see me? -->

Thanks @ju52 and @zwbetz.

I guess my post wasn’t clear. Sorry about that. I’m not interested in adding an actual comment to my code. Instead, I was wondering if there is a clearer way of writing:

{{range where .Pages "Layout" "" ""}}

It’s the "" "" that I don’t like.

A stylized example would be:

{{range where .Pages "Layout" "in" "Builtin"}}

Builtin denoting the standard Hugo layouts, index, list, single etc.

What about?

{{range where .Pages "Layout" "==" ""}}
1 Like

I think that’s better. Thanks for the suggestion.

@zwbetz
You are right, I know this, was a typo !