If statement doesn't seem to work

Support MB Views If statement doesn't seem to workResolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #27299
    HenriHenri
    Participant

    Hi Metabox,

    I've added the following MB view as a shortcode block:

         {{ post.online_evenement }}
            {% if '{{ post.online_evenement }}' != 1 %}
                <h3>Locatie {{ post.online_evenement }}</h3>
                <div class="locatie_gegevens">
                    <div>
                        {{ post.naam_bedrijf }}
                    </div>
                    <div>
                        {{ post.straat }} {{ post.straat_nummer }}
                    </div>
                    <div>
                        {{ post.postcode }} {{ post.stad }}
                    </div>
                    <div>
                        {{ post.land }}
                    </div>
                </div>
            
            {% endif %}

    The field Post.online_evenement is a checkbox, so it has a value of 1 if checked and a value of zero if it is not checked. The MB view displays the value when rendered, but it also displays the content between the if statement, no matter if the field is checked or unchecked. See the following screen recording: https://share.getcloudapp.com/4gu22RmY

    What am I doing wrong in the if-statement? Can you help me?

    Kind regards, Henri

    #27308
    Long NguyenLong Nguyen
    Moderator

    Hi Henri,

    You just need only the variable without wrap it in the curly bracket or single quote in the if statement.

    {% if post.online_evenement != 1 %}

    Get more details here https://twig.symfony.com/doc/3.x/tags/if.html

    Refer to this topic https://support.metabox.io/topic/getting-return-values-from-php-functions-in-views/

    #27314
    HenriHenri
    Participant

    Hi Long,

    thanks for the quick answer. I was trying all kinds of things, but now I understand that {{}} are used to display / echo the value. I still have to learn a lot 😉

    Have a great day!

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