Jekyll and Data files with Real Time Examples

One of the most interesting features of Jekyll is the ability to separate out data elements from formatting elements using a combination of YAML and Liquid. This setup is most common when you’re trying to create a table of contents generally called Data Files.

Data files are a really amazing feature of Jekyll and it is very easy to create a table of contents to avoid repetition in your template.

Rather than just jumping into Data Files at the most advanced level, I’m going to start from ground zero with an introduction to YAML and how you can access basic values in your data files using Jekyll.

Imagine here’s a file called company.yml in your _data folder.


  name: John Smith
  department: Digital Marketing

Markdown & Liquid

  <li>Name: {{}}</li>
  <li>Department: {{}}</li>


Name: John Smith
Department: Digital Marketing

YAML on its own doesn’t do anything — it just stores your data in a specific structure that other utilities can parse.

Jekyll supports the loading data from YAMLJSON, and CSV files located in the _data directory. Note that CSV files must contain a header row.

Let’s start with a real-time example, we’ve created job listing page on our website, let’s see how I achieved this by using data file.

First, create a folder in your project titled “_data” and save it. This is where you’re going to store your files.

Now, create a file you want to store in the _data folder. We’re Creating current-jobs.yml file.

Here is an example of one of our data files in /_data/current-jobs.yml format:

- title: Creative Content Writer
  date: Oct 4, 2017
  url: creative-content-writer- title: Digital Marketing Manager
  date: Sep 19, 2017
  url: digital-marketing-manager- title: ReactJS Front-end Developer
  date: Aug 23, 2017
  url: react-js-front-end-developer- title: UI/UX Designer
  date: Aug 23, 2017
  url: ui-ux-designer

The data can now be accessed using in our HTML. The filename current-jobs.yml determines the variable name. This information can now be used in your templates or HTML files.

<ul class=”job-listing">
  {% for block in %}
    <a href=”{{ block.url | prepend: site.baseurl }}”>
        <div class=”job-title">
          {{ block.title }}
        <div class=”job-date">
          {{ }}
  {% endfor %}

I am using “for loop” to get the data from current-jobs.yml file. You can read more about the loop in this document.

Notice that in order to access the data file, you need to the use following code.

_data is the folder, current-jobs.yml is the name of the YAML file and jobs is our data which we want to get from this file.

Job Listing

The same approach can be applied to a range of cases. One related to the above is a list of images for the gallery with some details of your particular event or if your website has lots of pages so you might want to create navigation for the pages. Instead of hard-coding navigation links, you can run a program to retrieve a list of pages to build the navigation for your site.

I will explain “How to build the navigation” in next part of this article.