Jekyll Custom Variables

There a few ways of using jekyll custom variables one is to put for example the following in the _cofig.yml.

numbers:
  zero
  one
  two

Then from elsewhere in the site you can do the following:

{% for number in site.numbers %}
  {{ number | upcase }}
{% endfor %}

The above will output the numbers seen on json feed with upercase letters. The other way is to create a yml file within _data folder such as sabcategories.yml file

sabcategories:
  cache
  two
  three

Then on your post you can use in the front matter like so:

---
layout: post
title: Drush atrticle 1 title
category: tech
sabcategories: cache
---

From elsewhere in the site you can do the following:

{% for subcats in site.sabcategories %}
  <li><a href="">
   {{ subcats }}</a>
  </li>
{% endfor %}

And that will everything what you have in the sabcategories.yml file.

Iterating through json file

To iterate through json feed in jeyll you can do the following. Create a test.json file like so:

[
  {
    "name": "The Red Hot Chili Peppers",
    "members": [
      {
        "name": "Anthony Kiedis",
        "role": "lead vocals"
      },
      {
        "name": "Michael 'Flea' Balzary",
        "role": "bass guitar, trumpet, backing vocals"
      },
      {
        "name": "Chad Smith",
        "role": "drums,percussion"
      },
      {
        "name": [
          {
            "thing": "some thing"
          },
          {
            "thing": "some thing"
          }
        ],
        "role": "Lead Guitar"
      }
    ],
    "year": "2009"
  }
]

then on the template do this:

{% for test in site.data.test %}
 <li>
   {{ test.members[3].name[0].thing }}          
 </li>
{% endfor %}

To print both key and the value of the json object you can do this:

{% for test in site.data.test %}
  <li>
    {{ test.members[3].name[0].thing }}
    {% for members in  test%}
    {{ members[0] }}
    {% endfor %}
  </li>
{% endfor %}