avillafiorita / jekyll-datapage_gen

Generate one page per yaml record in Jekyll sites.
369 stars 80 forks source link

Cannot do groups in generated pages #35

Closed mitchs91 closed 6 years ago

mitchs91 commented 6 years ago

I used this plugin to create a staff directory. It has been absolutely flawless, but I was hoping to extend it to be able to create individual pages of grouped items.

So far I can make a page for each staff member, but I was hoping to also make a page for each state, and have every staff member within the state show. When I try to do that, it only shows one staff member from that state, and their associated data is all broken.

avillafiorita commented 6 years ago

... this is know, I know! :-)

We had a similar problem with our website and solved it using liquid conditions to filter the data.

That is, you create different pages, one per group, and then run through the staff members selecting only those relevant for the specific page.

Something along the lines of:

  {% if member.state == "past" %}

      ....

  {% end %}

A different matter is if you want to automatically create one page per state (e.g. if you have twenty different states). A quick solution could be that of defining another yaml data structure, let us say "states", which contains all the values for which you want to generate pages. In the layout of the "state" page, you could then loop over the staff members and filter like in the previous case.

A more structural solution is extending the syntax of the plugin to group over one field in the data. In case, have you got any suggestion on the syntax to adopt?

avillafiorita commented 6 years ago

... now I see!

I have updated the code to support conditional generation of pages. It should now be possible to generate pages in different subdirectories according to arbitrary boolean conditions you can set in _config.yml.

Have a look at the documentation of filter_condition and at the example site for more details.

Let me know if it solves your issue, so that I can close it.