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.


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

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, privacy policy and cookie policy

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