Section appear when I loop on posts


#1

Hello,

I want to build a website with three pages (home, blog, about).
So I have organized my /content and /layouts folders like this:

/content

content
     posts
       - post1.md
       - post2.md
     pages
       - blog.md
       - about.md

/layouts

layouts
     - _default
       - baseof.html
       - list.html
       - single.html
     pages
       - blog.html
       - single.html
     posts
       - list.html
       - single.html
    - index.html

All post_x.md have the parameter type: “posts” in front matter.

In the blog.html, I loop on the posts like this:

<ul>
	{{ range (where .Site.Pages ".Type" "posts") }}
		<li>
		{{ .Title }}
		</li>
	{{ end }}
</ul>

With this loop, I get post1, post2 and posts

Why do I get “Posts” as a post? … “posts” is a section not a post :-/
Is there something wrong in my loop ? How to remove “posts” from the result of my loop?


#2

Try

{ range (where .Site.RegularPages “.Type” “posts”) }}


#3

Thanks, it’s works :slight_smile:

I will check the documentation to understand the difference between .Site.Pages and .Site.RegularPages


#4

Easy: .Site.Regular.Pages are pages which you created in content and .Site.Pages are definitely all pages including the ones which are automatically generated by Hugo (so called nodes).


#5

If it sounds easy, it usually isn’t. Your specification isn’t accurate, but this should be in the documentation.