1
votes

I'm using Jekyll to build a portfolio showcasing my design work. I'm getting confused on whether I should use a 'data' file (yml) and loop through content on my templates or use 'collections'.

My content is structured like this:

Homepage:

  • Featured Item
  • Client Hero 1
  • Client Hero 2
  • Client Hero 3
  • Client Hero 4
  • Client Hero 5

All of these link to their respective 'Client' page where i'll have images as jpgs in the same format for all case studies.

I'm confused on how to best use data, collections, etc to build out my site while keeping updating as efficient as possible.

My current solution uses _data/projects.yml where i have defined for 5 clients:

  • category: Pitch
  • description: "Lorem Ipsum Dolar Erat"
  • title: "Client John Smith"
  • shortname: "john-smith"
  • publish: false
  • featured: true

All of this is looped through and featured on the homepage. Now, I can create each post myself and add content manually but i believe there is a better way. How can I use collections and/or multiple individual project data files to best address this?

My idea situation would be defining content in yml or data files for each individual client and having 10 images, numbered 1 to 10 automatically brought in from /client name/ into a client layout.

1
Unfortunately data cannot be output to pages, see: github.com/jekyll/jekyll/issues/2983. Hope this can change in the future...Ray Shan

1 Answers

1
votes
  1. collection are beta, so, not production ready. Just don't use them as they can break without notice.
  2. data are not creating pages, an if you want to refer to data file from a page/post, you have to loop over to get a match between site.data.client and page.client or post.client. This is an option but you will have datas in page/post and in data files. all over the place.
  3. creating a page/post with front-matter custom vars ensure that you get all datas in same place. And you can easily loop over page/post variables to get things done.

I prefer #3 and in any client/clientName.html I personally do :

---
category: Pitch
description: "Lorem Ipsum Dolar Erat"
title: "Client John Smith"
shortname: "john-smith"
publish: false
featured: true
img:
    - img-02.jpg
    - img-03.jpg
---
{% include _client.html %}

That's it : all in the same place. And on the home page you can loop with :

{% for page in site.pages %}
    {% if page.category == 'Pitch' and page.featured = 'true' %}

And also loop over page/post.img

The idea is to get all in the same place. But it's really up to you.

Happy Jekyll !