How do I concatenate a string variable in a loop?

Hi There,

I’m trying to create a variable and depending on the condition, assign and concatenate various string slogans. Here’s what I have so far in liquid – unfortunately, it’s not working but I’m hoping someone can guide me to get the code below to work properly.

Much appreciated in advance!

Best,
CF.

{% for tagID in product.tags %}
  		{% assign cf_tag_name = '' %}
  
      {% if tagID contains 'deal' %}
      	{% cf_tag_name = 'Awesome Buy' %}
      {% endif % }
      
      {% if tagID contains 'eggs' %}
      	{% cf_tag_name = cf_tag_name | append: ' +  Free Range' %} 
      {% endif % }
         
      
        {{ cf_tag_name }}
      

      
    {% endfor %}

Try this one

maybe this can work for you

{% for tagID in product.tags %}
{% assign cf_tag = ‘’ %}

{% if tagID contains ‘deal’ %}
{% cf_tag_name = ‘Awesome Buy’ %}
{% endif % }

{% if tagID contains ‘eggs’ %}

{% capture cf_tag_name %}
{{cf_tag | append: ’ + Free Range’ }}

{% endcapture %}
{% endif % }

{{ cf_tag_name }}

{% endfor %}