Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more
Hey there,
Just having this error on a snip section of my collection page:
{% for product in collection.products %}
{% assign sale = product.compare_at_price and product.compare_at_price != product.price %}
{% assign sold_out = product.available %}
<li class="card " style="position relative; padding:10px">
{% if product.compare_at_price and product.compare_at_price != product.price %}
<div class="position_absolute--mix product_ribbon--style product_sale--style text-center fw-bold" style="top:0;right:0;">SALE</div>
{% else if product.available == false %}
sold out
{%endif%}
<a href="{{ product.url | within: collection }}">
<img class="card-img-top" src="{{ product.featured_image.src | img_url: 'x400' }}" alt="{{ product.featured_image.alt | escape }}">
</a>
<div class="card-body text-center">
<a class="card-title" href="{{ product.url | within: collection }}"><p>{{ product.title }}</p></a>
<h5 class="fw-semibold">{{ product.price | money }}</h5>
</div>
<form id="form-{{product_item.handle}}" method="post" action="/cart/add">
<input type="hidden" name="id" value="{{product_item.variants.first.id}}">
<a onclick="document.getElementById('form-{{product_item.handle}}').submit()" class="btn primary_btn--style" >ADD</a>
</form>
{% unless product.available %}<br><strong>sold out</strong>{% endunless %}
</li>
{% else %}
<p>no matches</p>
{% endfor %}
I'm trying assign this variable as a conditional statement. Am I missing something? Thanks!
Solved! Go to the solution
This is an accepted solution.
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 %}
This is an accepted solution.
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