Search code examples
jekyllliquid

How to list all pages in a folder using Jekyll?


I've got a folder with many markdown files which are pages. I would like to list in my header links to all of them. How can I do this in Jekyll?


Solution

  • You can use a collection object and iterate over it.

    If the folder with html pages is named _articles:

    1. define a collection in _config.yml, like:
    collections:
      articles:
        output: true # to make jekyll generate html pages
    
    1. iterate over them in any html view, like
    {% for article in site.articles %}
      <a href="{{ article.url }}"> link to article </a>
    {% endfor %}
    
    

    You can read more about collections here: https://jekyllrb.com/docs/collections/