Jabba Da Hoot
Jabba Da Hoot

Reputation: 804

Loop through files in _posts subfolder - Jekyll

I am using Prose.io as my CMS for github. In which I have set the root directory to /_posts. In /_posts I have made a folder "staticpages", this contains some markdown files with text. Can I loop through these files? I can't seem to figure out how.

So my file tree looks like:

root
   |
   _posts/
      |
      staticpages/
         |
         myfile.md

And I want to:

{% for pages in posts.staticpages %} {{ page.title }} {% endfor %}

Upvotes: 0

Views: 1249

Answers (2)

yorammi
yorammi

Reputation: 6458

You can browse to a folder by setting it in the URL. If the default URL is:

http://prose.io/#<account>/<repository>/

Then you can add the branch and folder relative path in the URL:

http://prose.io/#<account>/<repository>/tree/master/_posts/staticpages

Upvotes: 0

astark
astark

Reputation: 639

Here you go:
In your _config.yml you specify

defaults:
  - scope:
      path: "_posts/staticpages"
    values:
      static: "true"

and in your layout file (or page) you filter the posts and loop with:

{% assign posts = site.posts | where:"static", "true" %}
{% for post in posts %}...

This works very well for me...

Upvotes: 4

Related Questions