Looping in posts from another file than index.html

Is it considered to allow looping in posts from within another file than an index.html?

You can already loop on posts wherever you want. That’s what archives of related pages do most of the time, it works also for tag and categories pages. Why do you think otherwise?

I have the following structure:

categoryA
    | index.md
    | categoryB
        | index.md
        | _posts
            | article.md

I use a layout so that the loop adapts to the category to show the relevant posts.
My loop in categoryB/index.md is working, but the same on article.md doesn’t work. Any idea why?

You may need more information, so you can take a look at the repo if you need. The loop is at line 26 of the include nav-poemes.html which is included in two layouts: a) recueil.html and b) poem.html. The loop outputs correctly in the index.md that calls the recueil.html layout, but not in the article.md that calls the poem.html layout.

I checked that the include parameter nomrecueil that’s in the loop is well passed through both layouts. No posts are fetched in the second layout with the same loop…

This StackOverflow answer managed to make the loop work, but through a sinuous workaround…