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.

  • Where are you trying to display the field value? Twig has the empty test which may be of interest! – August Miller Jan 23 at 19:55
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 %}
|improve this answer|||||

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.