S
S
Stepan S.2015-03-04 03:45:39
ruby
Stepan S., 2015-03-04 03:45:39

How to count the number of values ​​in YML using Liquid?

There is an advertisers.yml YML file.
You need to count the number of campaigns with status = 1

- login: ivanivanov
  name: Иван Иванов
  campaigns:
    - name: Кампания Ивана Иванова
      status_id: 1
    - name: Вторая кампания Ивана Иванова
      status_id: 2
- login: ivanpetrov
  name: Иван Петров
  campaigns:
    - name: Кампания Ивана Петрова
      status_id: 1
- login: ivansidorov
  name: Иван Сидоров
  campaigns:
    - name: Кампания Сидорова
      status_id: 3

It seems like the code * should be like this:
{% assign advertiser = site.data.advertisers %}
{% assign campaign = advertiser.campaigns %}
{% if campaign.status_id == 1 %}
{{ campaign.status_id | size }}
{% endif %}

But it doesn't work
*Used by Jekyll

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question