Reputation: 193
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.
Upvotes: 0
Views: 136
Reputation: 193
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 %}
Upvotes: 0
Reputation: 52809
Not displayed categories array :
{% assign noDisplay = "one,two,three" | split: "," %}
=> ["one", "two", "three"]
The test :
{% unless noDisplay contains category[0] %}
{{ category[0] }}...
{% endunless %}
Upvotes: 0