Is it possible to loop over subfolders in Jekyll?

Viewed 670

I'm currently trying to loop over a subfolder in Jekyll but I don't know whether this is possible.

My folder structure looks like this:

_includes
_layouts
_pages
   folder_1
   folder_2
index.html

For example, I want to reach folder_1 by a loop how can I do this?

{% for page in pages.folder_1 %}

//xyz

{% endfor %}

What I want is that I've a static page and on this page I want to display the title and the description of each page in one of the subfolders.

Could you please help me?

1 Answers

Avoid naming main folder with an underscore unless you are using the _posts folder.

Then filter posts or pages checking their path:

{% assign folder1 = site.pages | where_exp: "item" , "item.path contains 'folder1'"%}
{% for item in folder1 %}
{{item.title}}
{% endfor %}
Related