2

Assuming I have a list of tags: iFix_6.3, iFix_7.0, iFix_7.1, iFix_8.0, announcement, and so on... and I want to run an operation only on certain several tags. How can I check for these multiple values?

There is contains, but I'm looking for the opposite of it and for multiple values...

Here is an example where I actually filter out all posts that contain the iFix_6.3 tag, thus display all other posts. This actually does not work yet... plus needs to be extended to work for multiple tags.

// posts with iFix_xxx tag should be filtered from the main posts view.
{% assign postUpdates = site.posts | where_exp:"item", "item.tags != 'iFix_6.3'" %} 
{% for post in postUpdates limit:10 %}
<div class="postItem inline">
    <p class="postDate">{% if post.pinned %}<span class="glyphicon glyphicon-pushpin"></span>{% endif %}{{post.date | date: '%B %d, %Y'}}</p>
    <p class="postTitle"><a href="{{site.baseurl}}{{post.url}}">{{post.title}}</a></p>
</div>
{% endfor %}
Idan Adar
  • 44,156
  • 13
  • 50
  • 89

2 Answers2

1

You can do this by building an array of excluded tags (excluded_tags) using split and a string of the comma-separated tags. Then for each post, you iterate on the post's tags. Check if the tag is in excluded_tags using contains, if it is then raise the flag filtered_out to not display the post, using the unless control flow tag.

{% assign excluded_tags = "iFix_6.2,iFix_6.3,announcement" | split : "," %}

{% for post in site.posts limit:10 %}
   {% assign filtered_out = False %}
   {% for tag in post.tags %}
       {% if excluded_tags contains tag %}
           {% assign filtered_out = True %}
           {% break %}
       {% endif %}
   {% endfor %}

   {% unless filtered_out %}
       ...
   {% endunless %}
{% endfor %}
jrbedard
  • 3,662
  • 5
  • 30
  • 34
0

Seems unless would solve the case.

{% assign postUpdates = site.posts | where_exp:"item", "unless item.tags contains 'iFix_6.3'" %} 
eQ19
  • 9,880
  • 3
  • 65
  • 77