Custom Fields
Re-Envisioned
Support MB Views Show only if field not blank

  • Creator
    Topic
  • #29918
    Resolved Andrew
    Participant

    I have a custom field called orange_button set to display on pages. I created a View and tried to use a Twig if statement to only output some HTML if the field is not empty. Basically the field will contain a link to a page on the site which will display a button if the value is set or nothing if it is not.

    This is my current if statement:

    {% if '{{ post.orange_button }}' is empty %}
    <span>No Value</span>
    {% else %}
    <a href="{{ post.orange_button.url }}">Book Your Free Consultation</a>
    {% endif %}

    But it just always shows the button regardless if the field is empty or not?

    I'm totally new to =meta and twig so can anyone please point me in the right direction?

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

    Hi Andrew,

    Using a double of open and closing curly bracket means printing out the variable. If you want to compare it in a condition, please just remove them.

    {% if post.orange_button is empty %}
    
    #29943
    Andrew
    Participant

    Hi Long,

    Got it working thanks to your advise. Thank you very much.

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