Twig condition on cloned group field

Support MB Views Twig condition on cloned group fieldResolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #45979
    EddyPiVEddyPiV
    Participant

    Hi,

    I have a cloned group field, with 2 fields: video_type and video
    In the View I want to show these fields. Not a big deal.

    But I want to show a header <h3>Videos</h3> first, but only if there are videos added.
    So no videos, then no header.
    How do I do that with the Twig condition, or is there another way?

    #45986
    PeterPeter
    Moderator

    Hello Eddy,

    You can check the array of video subfield is not empty and output a heading before using the loop to show the video. Here is an example:

    {% if post.group[0].video is not empty %}
        <h3>Videos</h3>
    {% endif %}
    
    {% for clone in post.group %}
        {% for item in clone.video %}
            {{ item.rendered }}
        {% endfor %}
    {% endfor %}
    #45987
    EddyPiVEddyPiV
    Participant

    Thanks Peter. Fully makes sense, I just didn't think of it myself.

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