简体   繁体   中英

Jekyll - Liquid Templating - Exclude a Category from Widget

I am attempting to rebuild a sidebar widget which shows my categories used in Jekyll. It works fine as it is now. I want to change the liquid templating to exclude one specific category link from being shown in this widget.

{% assign cat_list = site.categories %}
  {% if cat_list.first[0] == null %}
    {% for category in cat_list %}
      <li><a href="{{ site.baseurl }}/categories#{{ category }}">{{ category }} <span class="cat-count">{{ cat_list[category].size }}</span></a></li>
    {% endfor %}
  {% else %}
    {% for category in cat_list %}
      <li><a href="{{ site.baseurl }}/categories#{{ category[0] }}">{{ category[0] }} <span class="cat-count">{{ category[1].size }}</span></a></li>
    {% endfor %}
  {% endif %}
{% assign cat_list = nil %}

I think what I want is something like

{% for category in cat_list **UNLESS category = 'CATEGORY'** %}

But that did not work. I'm kinda stuck, is this possible?

Thank You.

Not displayed categories array :

{% assign noDisplay = "one,two,three" | split: "," %} {% assign noDisplay = "one,two,three" | split: "," %} => ["one", "two", "three"]

The test :

{% unless noDisplay contains category[0] %}
{{ category[0] }}...
{% endunless %}

Thank you, @David Jacquel

{% assign noDisplay = "CATEGORY" | split: "," %}
{% assign cat_list = site.categories %}
  {% if cat_list.first[0] == null %}
    {% for category in cat_list %}
      <li><a href="{{ site.baseurl }}/categories#{{ category }}">{{ category }} <span class="cat-count">{{ cat_list[category].size }}</span></a></li>
    {% endfor %}
  {% else %}
    {% for category in cat_list %}
    {% unless noDisplay contains category[0] %}
      <li><a href="{{ site.baseurl }}/categories#{{ category[0] }}">{{ category[0] }} <span class="cat-count">{{ category[1].size }}</span></a></li>
      {% endunless %}
    {% endfor %}
  {% endif %}
{% assign cat_list = nil %}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM