Custom Fields
Support MB Blocks Using the value of a switch field in a twig if statement

  • Creator
  • #32951
    Resolved Kyle Melton


    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!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Author
  • #32954
    Long Nguyen

    Hi Kyle,

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

    {% if multiple_switch == "On" %}
    Kyle Melton

    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:

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

    Thanks again!


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