Content list template pulling in itself

I have a news feature on a site where the landing page must list the sub news articles, this is working fine apart from the fact that the listing is also pulling in itself when building? Should I be creating the list a different way to:

{{ range where .Site.Pages “Type” “news” }} (Where type is the section)

Or is there a way to prevent the listing from pulling in itself?


Could you provide your directory structure which will help us with detail?

If you are pulling data in that format, It pulls up everything, may be you could use the .File.BaseFileName to exclude the current file or Section for the section.

See the documentation - (File Variables in the link)

My directory structure is


I then have my layouts within a theme


Looking at the examples for list templates they seem to use .Data.Pages to list the content but when I try that it doesn’t render anything. This is my first time using Hugo so I am not sure what I am doing wrong.

Is file?

Try using .Site.Pages instead of .Data.Pages

In default/_list.html page you can do this

{{ range .Data.Pages }}
  {{ .Render "summary"}}
{{ end }}

In a post/partial page, you can use .Site.Pages instead of .Data.Pages to achieve the same.

newsarticle is a folder with an file within, should they not be folders and just markdown files listed in the news content section? Because the news area is just an area within a larger site I needed a .md file for the news listing page to add content above the listing

The below is what I am using at the minute which is also pulling in itself because there is a .md file for the list page too

{{ range where .Site.Pages "Type" "news" }}
  {{ .Render "single" }}
{{ end }}


{{ range where .Data.Pages }}
  {{ .Render "single" }}
{{ end }}

Renders nothing


I have got it working using your first suggestion and looking at the .File.BaseFileName

Thanks for your help,

they can either be in folders. if its a single one, better to keep it with unless you intend to add sub-articles under the same story.

You can even configure the slug/permalink instead of configuring the peramlink as the filename