Twiq if condition with Checkbox List

Support MB Views Twiq if condition with Checkbox ListResolved

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #33120
    KhairulKhairul
    Participant

    Hi,

    I'm trying to display a text on MB View depending on the checkbox list value with Twig.

    For example, let's say I've created a checkbox list with choices A, B, C and D. Choices A and D are ticked in the post. I want to display the text if the checkbox list contains A.

    I tried the code below in views, however it's not working.

    
    {% if post.checkbox_list_id contains 'A' %} diplay something {% endif %}
    

    Any advice on how to proceed. Sorry, I'm new at this.

    Thanks in advance.

    #33126
    Long NguyenLong Nguyen
    Moderator

    Hi,

    Thank you for reaching out.

    Here is an example to check a value in the choices of the checkbox list.

    {% set value = 'a' %}
    {% for item in post.checkbox_list %}
        {% if value in item %}
            Checked!
        {% endif %}
    {% endfor %}
    #33133
    KhairulKhairul
    Participant

    Hi,

    Perfect. Thank you so much for your help – really appreciate it.

    #34070
    KhairulKhairul
    Participant

    Hi,

    Sorry for reviving old topics, I've stumbled upon another problem.

    How do I display the output if value is unchecked?

    I tried the above code with "if value not in item", but it doesn't work.

    Thanks.

    #34091
    Long NguyenLong Nguyen
    Moderator

    Hi,

    Please try again with this one

    {% set value = 'a' %}
    {% set checkbox_list = mb.rwmb_meta('checkbox_list') %}
    {% if value in checkbox_list %}
        Checked!
    {% else %}
        UnChecked!
    {% endif %}

    I've fixed the code a little bit. Using the helper function rwmb_meta() to get the raw value of the field checkbox_list.

    #34098
    KhairulKhairul
    Participant

    Hi,

    That works great. Thank you again Long.

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