Hide certain tags from filter function

Solved
Anne-Marieke
Tourist
7 0 1

Hi everyone,

I use tags in my webshop for customers so they can filter on certain products that they're searching. But I would like to use tags for me as well in de the backend without customers seeing them.

I know there are several ways to import this. I found this that I would like to use: 

<div class="clearfix filter">
  <p>Browse by tag:</p>
  <select class="coll-filter">
    <option value="">All</option>
    {% for tag in collection.all_tags %}
      {% assign prefix = tag | slice: 0 %}
      {% if prefix == '_' %}
        {% continue %}
      {% endif %}
      {% if current_tags contains tag %}
        <option value="{{ tag | handle }}" selected>{{ tag }}</option>
      {% else %}
        <option value="{{ tag | handle }}">{{ tag }}</option>
      {% endif %}
    {% endfor %}
  </select>
</div>

So if I start a tag with _ it doesn't how up in the frontend of the webshop. 

But I can't seem to find the exact spot where I should add this code. I took over this webshop from a colleague that isn't working with us anymore, and I don't always understand his coding.

If you would like to check on a page I want to implement this: https://bickerykerst.nl/collections/happy-jul

Somewhere here?

    {% if is_filter_by_available or section.settings.sort_enable %}
      <div class="filters-toolbar-wrapper{% if is_filter_by_available %} filters-toolbar--has-filter{% endif %}">
        <div class="page-width">
          <div class="filters-toolbar">
            <div class="filters-toolbar__item-wrapper">
              {% if section.settings.tags_enable %}
                {% unless collection.all_tags.size == 0 %}
                  <div class="filters-toolbar__item-child">
                    <label class="filters-toolbar__label select-label" for="FilterTags">{{ 'collections.filters.title_tags' | t }}</label>
                    <div class="filters-toolbar__input-wrapper select-group">
                      <select class="filters-toolbar__input hidden" name="FilterTags" id="FilterTags" aria-describedby="a11y-refresh-page-message a11y-selection-message" data-select-input>
                        <option value="{{ collection.url }}">{{ 'collections.filters.all_tags' | t }}</option>
                        {% for tag in collection.all_tags %}
                          {%- assign new_url = tag | link_to_tag: tag | split: 'href="' | last | split: '"' | first -%}
                          <option value="{{ new_url }}"{% if current_tags contains tag %} selected="selected"{% endif %}>{{ tag }}</option>
                        {% endfor %}
                      </select>
                      {% include 'icon-chevron-down' %}
                    </div>
                  </div>
                {% endunless %}
              {% endif %}

 Sorry and thanks in advance, I don't have a lot of knowledge of coding/liquid. 

0 Likes
Amarjyoti
Tourist
20 7 12

Hey @Anne-Marieke,

Replace this:

{% for tag in collection.all_tags %}
    {%- assign new_url = tag | link_to_tag: tag | split: 'href="' | last | split: '"' | first -%}
    <option value="{{ new_url }}"{% if current_tags contains tag %} selected="selected"{% endif %}>{{ tag }}. </option>
{% endfor %}

 
With this:

{% for tag in collection.all_tags %}
  {% if tag contains '_' %}
  {%- assign new_url = tag | link_to_tag: tag | split: 'href="' | last | split: '"' | first -%}
  <option value="{{ new_url }}"{% if current_tags contains tag %} selected="selected"{% endif %}>{{ tag | split: '_' | last }}</option>
  {% endif %}
{% endfor %}


And let me know if it works for you or not.

Thank you!! 

Amarjyoti | I'm here to help and share some insights. Not looking for work.
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
0 Likes
Anne-Marieke
Tourist
7 0 1

@Amarjyoti thank you for your response

I changed the code, but now only the tags with '_' in front will show up in the frontend of the store, whereas I don't want the _tags to show up, only the tags without a _ prefix. 

 

0 Likes
Amarjyoti
Tourist
20 7 12

This is an accepted solution.

Hey @Anne-Marieke,

Got it. Can you please replace that code with the below one?

{% for tag in collection.all_tags %}
  {% unless tag contains '_' %}
  {%- assign new_url = tag | link_to_tag: tag | split: 'href="' | last | split: '"' | first -%}
  <option value="{{ new_url }}"{% if current_tags contains tag %} selected="selected"{% endif %}>{{ tag }}</option>
  {% endunless %}
{% endfor %}

 
Let me know if this works.

Thank you!!

Amarjyoti | I'm here to help and share some insights. Not looking for work.
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
Anne-Marieke
Tourist
7 0 1

@Amarjyoti Yess, thank yóu! That did the trick ^_^