Show only if field not blank

Support MB Views Show only if field not blankResolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #29918
    AndrewAndrew
    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?

    #29931
    Long NguyenLong 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
    AndrewAndrew
    Participant

    Hi Long,

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

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