Why am I getting a liquid variable assignment error on my collection page?

Hey there,

Just having this error on a snip section of my collection page:

Liquid syntax error (sections/collection-template.liquid line 2): Expected end_of_string but found id in “{{product.compare_at_price and product.compare_at_price != product.price }}”
Code:

{% for product in collection.products %}
        {% assign sale = product.compare_at_price and product.compare_at_price != product.price %}
        {% assign sold_out = product.available %}
        - {% if product.compare_at_price and product.compare_at_price != product.price %}
                
  SALE

              {% else if product.available == false %}
                  sold out
              {%endif%}
            
                
            
            

            

  {{ product.title }}

              ##### {{ product.price | money }}
            

            
              {% unless product.available %}
  **sold out**{% endunless %}
        

  {% else %}
    

no matches

  {% endfor %}

I’m trying assign this variable as a conditional statement. Am I missing something? Thanks!

You can’t assign a variable as a condition like this. You’ll need to initialise it first, then reassign it inside an if statement.

{% assign var = false %}
{% if condition %}
  {% assign var = true %}
{% else %}
  {% assign var = false %}
{% endif %}

Oh okay awesome thanks! I was just following that from a Udemy Course too… but i guess maybe that was outdated code?

Thanks for the help.

Hi,

I have met the same problem after I installed a new theme ella newest vision.

Liquid syntax error (collection-template-default line 15): Expected end_of_string but found id in “{{optionproduct-title change-text}}”

It shows on my every collection page and cannot show the products correctly, but it is fine on my home page.

Could you please tell me how to fix it?

Thank you so much.

Best,

Lucas