Using the value of a switch field in a twig if statement

Support MB Blocks Using the value of a switch field in a twig if statementResolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #32951
    Kyle MeltonKyle Melton
    Participant

    Hi,

    I am trying to create an if statement using a switch field but it seems to not render.

    Here is what I have tried for the beginning of the statement:

    The switch field has an ID of "multiple_switch"

    {% if multiple_switch == 1 %}

    {% if multiple_switch == '1' %}

    {% if multiple_switch == "1" %}

    {% if multiple_switch == true %}

    All of the above either do nothing or show the content regardless of the switch setting.

    Is there something I am overlooking?

    Thank you!

    #32954
    Long NguyenLong Nguyen
    Moderator

    Hi Kyle,

    The field switch returns the value On/Off, please compare it with that value.

    {% if multiple_switch == "On" %}
    
    #32956
    Kyle MeltonKyle Melton
    Participant

    Hi Long,

    Thank you for the clarification.

    I assumed it had to be a 1 or a 0 because of this part of the documentation:

    Data
    This field saves the “on” and “off” status in the database as “1” or “0”.

    Thanks again!

    Kyle

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