Looping over subsets of nested content

If I have content in the following nested layout:

writing/article1.md
writing/article2.md
writing/personal/article3.md
writing/personal/article4.md

How do I only refer to the top-level articles in writing/ for the /writing/ index page (while ignoring articles in writing/personal)?

Along the same lines, how do I refer only to articles in writing/personal in the /writing/ index page?

Looping over .Data.Pages in /writing/ gives me all articles. And I am unable to use either .Type or .Section to differentiate between the two kinds of articles.

I solved this by splitting and checking the .RelPermalink variable, and using the len to work out where the page was in the path (my aim was to categorise by folder and file location), which then meant the one before it in the array (of the split variable) was the final sub folder

1 Like

Thank you. I was starting to go down this path on my own but I couldn’t get this to work without the ‘split’ that you mention.

Will try it with that and now I am confident it should work out. :grinning:

This is what I used:

{{ $link_array := split .RelPermalink “/” }}

I also used this the substr command to chop off the last or the first ‘/’ (don’t remember which), but there might be a better way to do that.

I am able to do things like the following within the individual page template (instead of using len as you mentioned):

 {{ if in (split .RelPermalink "/") "personal" }}personal{{ end }}

But how do I do the same thing within the index page? I am not able to access split on .RelPermalink as easily. The closest my experiments have gotten are:

  {{ range where .Data.Pages "RelPermalink" "in" "/writing/personal/specific-post/" }}
  {{ .Render "summary"}}
  {{ end }}

What I am really looking to do, in my hypothetical syntax is the following:

{{ range .Data.Pages where "personal" "in" (split "RelPermalink" "/") }}
    do something
{{ end }}