Jekyll: collections vs data file
Asked Answered
I

1

7

What are the advantages of using collections than data files? They seem to be able to achieve the same purpose. Plus usually we have data files of items (e.g. JSON, csv), then I have to transform them if using collections. The differentiation between posts vs collections/datafile is clearer but I am confused when should I use collections vs data files.

Interplay answered 13/9, 2019 at 0:59 Comment(0)
G
7

TL;DR:

  • Collection—Will have its own page, URLs, and possibly an index page.
  • Data—Will not have its own page, but will be referenced to on other pages within the site.

Longer answer:

In practice, collections and data are very similar.

A good way to think of the difference is: collections generally have their own page, data are supplemental information that you want to load dynamically or reuse on more than one page.

So for example, I manage a website that includes many user testimonials that are referenced on specific project pages. Testimonials do not have their own page, and there's no index of testimonials. So I use a data yaml testimonials.yml file for those.

The site has projects (it's a professional portfolio), and each project has its own page, URL, etc. In this case, I define a collection for my projects.

Jekyll blog posts are basically just a collection that's pre-defined.

Gustaf answered 16/7, 2020 at 10:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.