1

Is there a way to differentiate the number field value empty and 0?

I would like to display this field only when there's a value in the field even though the value is 0.

But when I input 0 into the field, it seems that Craft thinks the value is empty... so doesn't still display the field.

Thanks.

1
  • Where are you trying to display the field value? Twig has the empty test which may be of interest! Commented Jan 23, 2020 at 19:55

1 Answer 1

1

Twig's is not null should work for this. Assuming you have a Number field called number and you're looping through a list of entries, something like this should work:

{% for entry in entries if entry.number is not null %}
    {{ entry.number }}
{% endfor %}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.