Custom Fields
Re-Envisioned
Support MB Views Number field condition in Views

  • Creator
    Topic
  • #18729
    Resolved Trang Nguyen
    Participant

    Hi, I have a Number field, I want to set 3 results that depend on the value of this field:

    {% if post.price == 0 %}
        <p>Free</p>
    {% elseif post.price > 0 %}
        <p>{{ post.price }}</p>
    {% else %}
        <p>No info</p>
    {% endif %}

    It works with the condition == 0 and > 0 but for the {% else %} (empty or > 0) it always show “Free” (the same to condition == 0).

    How do I fix this to show “No info” when the price is != 0 neither > 0?

    Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Author
    Replies
  • #18736
    Long Nguyen
    Moderator

    Hi,

    Your code works great with a number > 0 or = 0 (same with empty value)

    If you want to set the negative number (last else condition), you can set min to the number as you want such as -100 or PHP_INT_MIN with PHP version >= 7.0 or step to any for the floating numbers.

    For further information, please follow the Number field documentation

    #18780
    Trang Nguyen
    Participant

    Thank you, Long. It works.
    I was thinking ‘0’ is different from ’empty’ so in case I leave the field empty it will show ‘No Info’.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.