Hey y’all!
I’m working on the boss’s shop and have run into some funky behavior. My goal is to strip the whitespace from a string so the code can build a product block from the resulting handle, giving me, in this example, “gem-chip-jars”.
Here’s the relevant Liquid/HTML code:
{% assign my_description = article.content | split: '
' %}
{% assign my_description_size = my_description.size %}
{% for i in (1..my_description_size) %}
{% if my_description[i] contains '[product]' %}
{%- assign handle_product = my_description[i]| remove: ' ' | remove: ' ' | remove: '\n' | strip_html | remove: '[product]' | strip -%}
{% else %}
{{ my_description[i] }}
{% endif %}
{%- endfor -%}
However, strip, rstrip, and {%- xxx -%} are not removing the whitespace at the end of the string, which gives me this result (white space and line break included):
There is no product with the handle "gem-chip-jars " so the code is not executed. I’ve tried every combination of strip, rstrip, replace, and remove that I can think of, and even splitting up the string filters step-by-step, but I still can’t get rid of that trailing space.
I realize that I can just, y’know, NOT put a trailing space at the end, but at this point it’s the principle of the thing and I must beat it into submission for my own peace of mind (and just in case someone forgets to make sure that they haven’t inadvertently added extra spaces to the string).
Please tell me it’s something silly so I can get on with my life. TYIA!