0
votes

I'm trying to build a product list from products.yml located in the _data directory with a for loop in jekyll so that the end result would look like this: example built with handlebars.js

First I wrote a YAML file in _data/products.yml with a list of products divided into categories

---
categories:
- Baking Products:
  - name: Vegetable oil
  - name: Vinegar
  - ...
- Dairy Products:
  - name: Cream Cheese
  - name: Cottage Cheese
  - ...
- Other Products:
  - name: Peanut butter
  - name: Chocolate spread
  - ...

Now I want to iterate over all categories, and for evry cateory to iterate over all its products and displaying some info about them:

{% for category in site.data.products %}
  <div class="plist">
    <div class="category">
      <h3>{{ category.name }</h3>
      <span>Qty</span>
    </div>
    {% for product category.products %}
      <div class="product checkbox">
        <input type="checkbox" id="{{ product.name | capitalize }}" value="{{ product.name }}">
        <label  for="{{ product.name | capitalize }}">{{name}}</label>
        <select name="{{ product.name }}" id="{{ product.name | capitalize }}Q" autocomplete="off" class="dropdown">
          <option value="0">0</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option>
        </select>
      </div>
    {% endfor %}
  </div>
  {% if loop.index0 % 2 == 0 %}
    <break></break>
  {% endif %}
{% endfor %}

getting this error:

Liquid Exception: Liquid syntax error (line 13): Variable '{{ category.name }' was not properly terminated with regexp: /}}/ in order.html

jekyll 3.8.5 | Error: Liquid syntax error (line 13): Variable '{{ category.name }' was not properly terminated with regexp: /}}/

2
See this line: <h3>{{ category.name }</h3>ashmaroli
@ashmaroli see what? I don't understand please explain..Meir Roth
spent hours trying to figure it out.. couldn't find answer on the internetMeir Roth
Liquid variables need to be enclosed inside a pair of double-braces: {{ category.name }}ashmaroli
@ashmaroli ok I fixed that enclosed double-braces and it still gives me an error Liquid Exception: Liquid syntax error (line 16): Syntax Error in 'for loop' - Valid syntax: for [item] in [collection] in order.html jekyll 3.8.5 | Error: Liquid syntax error (line 16): Syntax Error in 'for loop' - Valid syntax: for [item] in [collection]Meir Roth

2 Answers

0
votes

Liquid Variable needs to be enclosed within double braces:

{{ category.name }}

and Liquid tags need to be a pair of brace-percents:

{% seo %}
0
votes

Ok here is the fixed code.

Thanks @ashmaroli

{% for category in site.data.products %}
  <div class="plist">
    <div class="category">
      <h3>{{ category.name }}</h3>    <!-- missing "}" -->
      <span>Qty</span>
    </div>
    {% for product in category.products %}   <!-- missing "in" -->
      <div class="product checkbox">
        <input type="checkbox" id="{{ product.name | capitalize }}" value="{{ product.name }}">
        <label  for="{{ product.name | capitalize }}">{{name}}</label>
        <select name="{{ product.name }}" id="{{ product.name | capitalize }}Q" autocomplete="off" class="dropdown">
          <option value="0">0</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option>
        </select>
      </div>
    {% endfor %}
  </div>
  {% cycle '','<break></break>' %}   <!-- fixed -->
{% endfor %}