How to remove a filter label part based on collection name in Liquid?

Hi, I’m trying to remove part of label of filter based on collection name. I’m setting the variable to have exactly same label name part I need to remove.

{% assign collection_title_base = collection.title | downcase | split: ' ' %}
{% capture collection_title_group %}
  {% for word in collection_title_base %}
    {{ word | capitalize }}
  {% endfor %}
{% endcapture %}
{% assign collection_title = collection_title_group | strip %}

But when I use as variable.. is not working.

<label for="{{ id }}">{{ value.label | remove: collection_title }}</label>

And if I test with string, works fine

<label for="{{ id }}">{{ value.label | remove: "Saline Sport" }}</label>

And when I print {{ collection_title }} render exactly [Saline Sport]

The ideia is to remove this filter option label part, based on collection title.

Has anyone had this problem?

To fix this, you can try trimming any extra whitespace from collection_title before using it in the remove filter. Here’s how you can adjust your code:

{% assign collection_title_base = collection.title | downcase | split: ' ' %}
{% capture collection_title_group %}
  {% for word in collection_title_base %}
    {{ word | capitalize }}
  {% endfor %}
{% endcapture %}
{% assign collection_title = collection_title_group | strip %}

If the problem persists, try debugging by outputting the collection_title and its length to see if there are any hidden characters:


Collection Title: '{{ collection_title }}'
Length: {{ collection_title | size }}

Hi @ToledoX82 ,

You can try using the {{ collection.title }} replace for {{ collection_title }}

Hope my solution works perfectly for you!

Best regards,

Oliver | PageFly

Hi, thanks for your reply… you aid “here’s how…” but looks that your code is same I previously sent.
I will try debug with size, but looks that this is the issue, ghosts chars.

Hi, yes that is my first try. The issue is that some collections are in uppercase, so I tried avoid ask to client rewrite all collections to captalize each word. And found the issue when split words and try capture string. This is coming with ghosts chars.