Create categories in Jekyll _data?

I need help using _data in Jekyll to create content.

Let's say I want to create a directory showing the countries that Twitter and Facebook have blocked. I understand how to query the _data folder, but how do I create something like categories in _data.yml and query this data?

Let me try to explain.

Twitter is blocked in Turkey and Iran, so I started with this (network.yml in _data):

- network: Twitter

      

This is where I got stuck. I don't understand if I want to "tag" or "categorize" Twitter like this:

- network: Twitter
  blockedcountries: [Turkey, Iran, Iraq]

- network: Facebook
  blockedcountries: [Iraq, Turkey]

      

Then I would like the pages on mysite.com/turkey/ to display turkey tagged networks. Something like that:

{% for network in site.data.networks %}
{% if network.blockedcountries == Turkey %}
        <li>{{ network.network }} is blocked in Turkey</li>
{% endif %}
{% endfor %}`

Which would display: 
 - Twitter is blocked in Turkey
 - Facebook is blocked in Turkey

      

Appreciate any help and prompt bitcoin if solved!

+3


source to share


1 answer


Your YAML is right. The problem seems to be in your if statement:

{% if network.blockedcountries == Turkey %}

      

network.blockedcountries is an array (list), so your if statement should be like this:

{% if network.blockedcountries contains "Turkey" %}
  <li>{{ network.network }} is blocked in Turkey</li>
{% endif %}

      

Jekyll uses Liquid markup language for its templates. You can read more about its capabilities here . Maybe a liquid case application is also helpful for further optimization.




Here is my "complete" solution:

My data is in _data / networks.yml

- name: Twitter
  blockedcountries: [Turkey, Iraq, Iran]
- name: Facebook
  blockedcountries: [Turkey, Iraq]

      

My fluid template in index.html

<ul>
  {% for network in site.data.networks %}
    {% if network.blockedcountries contains "Turkey" %}
      <li>{{ network.name }} is blocked in Turkey!</li>
    {% endif %}
  {% endfor %}
</ul>

      

+3


source







All Articles