How to iterate all pages in custom folders in jekyll

There are two primary document collections in Jekyll: posts and pages. Another will be collections if you use them.

Pages and posts may contain their own front matter, so I suggest you treat each one separately.

:writing_hand: List of all posts

Read the Jekyll array containing a list of all the posts:

{% assign posts = site.posts %}
{% for post in posts %}
    title: {{post.title}}
{% endfor %}

:page_facing_up: List of all pages

Read the Jekyll array containing a list of all the pages:

{% assign pages = site.pages | where_exp: 'page', 'page.title' %}
{% for page in pages %}
    title: {{page.title}}
{% endfor %}

Notice I used a where_exp filter in the list of pages. Sometimes a page does not have a title in the front matter. That will remove untitled pages from the listing. If you want all of them, even without a title, then the code would look like this instead:

{% assign pages = site.pages %}
{% for page in pages %}
    title: {{page.title}}
{% endfor %}

:arrow_right: More options

I recommend you check out the list of built-in Jekyll site variables. You can learn about the different arrays you can access that Jekyll automatically collects for you. There may be other document types (like HTML docs) that you want to include as well.