Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For - loop - else #19

Open
ghost opened this issue Feb 24, 2013 · 3 comments
Open

For - loop - else #19

ghost opened this issue Feb 24, 2013 · 3 comments

Comments

@ghost
Copy link

ghost commented Feb 24, 2013

{% for product in product %}
{{ product.name }}
{% else %}
No products found
{% endfor %}

does not work... would be great if could have that!

@chrstphrknwtn
Copy link

Your logic is broken, to acheive what you want you need to have an if statement for else to work. You need to have something like:

if there are products, then
for each product show some product information
else tell me there are no products

In liquid (based on shopify), it could look like this:

{% if collection.products.size > 0 %}
  {% for product in collection.products %}
    {{ product.name }}
  {% endfor %}
{% else %}
  No products found
{% endif %}

@ghost
Copy link
Author

ghost commented Apr 24, 2013

Well.. Since this is based on liquid it should work... I understand there is a more correct way of doing it..
But in the original liquid you can do it like i said without making an if statement

On 24 apr 2013, at 18:41, chrstphrknwtn [email protected] wrote:

Your logic is broken, to acheive what you want you need to have an if statement for else to work. You need to have something like:

if there are products, then
for each product show some product information
else tell me there are no products

In liquid (based on shopify), it could look like this:

{% if collection.products.size > 0 %}
{% for product in collection.products %}
{{ product.name }}
{% end for %}
{% else %}
No products found
{% endif %}

Reply to this email directly or view it on GitHub.

@chrstphrknwtn
Copy link

sorry, my mistake... the way you describe is indeed correct, and insomuch a bug for this php port.

harrydeluxe pushed a commit that referenced this issue Dec 13, 2016
escape should use htmlentities; escape_once should simply work
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant