A space to discuss online store customization, theme development, and Liquid templating.
Hi,
I'm coding in Liquid for my theme in order to search given keyword from collection.description. The problem is that the collection.description which is written by richtext editor has unintended and this   doesn't work same as normal space. I've been struggling so hard to find any helpful information from Shopify Community, but I cannot make it.
Here's a simplified example to describe the problem. Let's say the collection.description is "<p>Hello my world</p>" (You can see the same result only if the object contains ):
<!-- Code -->
{% assign keyword1 = " " %}
{% assign keyword2 = " " %}
{% assign keyword3 = "Hello my" %}
{% assign keyword4 = "my world" %}
{% if collection.description contains keyword1 %} TRUE {% else %} FALSE {% endif %}
{% if collection.description contains keyword2 %} TRUE {% else %} FALSE {% endif %}
{% if collection.description contains keyword3 %} TRUE {% else %} FALSE {% endif %}
{% if collection.description contains keyword4 %} TRUE {% else %} FALSE {% endif %}
<!-- Result -->
TRUE
FALSE
TRUE
FALSE
It happens only if is added by richtext editor (or any Shopify's end). If you replace the collection.description with another String variable of same value, all cases above return TRUE as follows:
<!-- Code -->
{% assign desc = "Hello my world" %}
{% if desc contains keyword1 %} TRUE {% else %} FALSE {% endif %}
{% if desc contains keyword2 %} TRUE {% else %} FALSE {% endif %}
{% if desc contains keyword3 %} TRUE {% else %} FALSE {% endif %}
{% if desc contains keyword4 %} TRUE {% else %} FALSE {% endif %}
<!-- Result -->
TRUE
TRUE
TRUE
TRUE
Because of this feature, I cannot use some Liquid filters with collection.description such as contains, replace and remove. Furthermore, this can happen not only with collection description, but also with product description, page content, and blog post.
Anybody who can figure out?
+1
I also can't manage to strip/remove/replace the additional ` ` at the end of my `product.description`.
So far I tried
LOL, while typing this I tried one more thing:
{%- assign stripped_description = product.description | remove: ' ' -%}
Just put a non-breaking space in there. Mac: ⌥ + Space
VSCode will warn you that it's bad practice, but 🤷🏻
For your example it works as well.
This is so ridiculous …