• Resolved grohlbainselic

    (@grohlbainselic)


    Hi there,

    I have this code:

    {% if member %}
    
    {% for item in member %}
    
    {% if item.status == 'wcm-active' %}
    
    ...
    
    {% endif %}
    {% endfor %}
    {% endif %}

    How can I get to simplify this code with something like {% if member.item.status %}? I don’t even know if this is possible.

    I’m trying to check if AT LEAST one item in the loop of member have the ‘wcm-active’ status.

    Thanks for advance for the great plugin! Been using it in all my projects.

Viewing 1 replies (of 1 total)
  • Hi! Have you tried the solution suggested in stackoverflow?

    For brevity and completeness the solution easier solution for your case would be something like this (I think):

    
    {% if items|filter(member.wcm-active => member.wcm-active|default)| length %}
        {% for item in items %}
            ... display audio ...
        {% endfor %}
    {% endif %}
    

    Either of the solutions posted in that SO thread, you are iterating twice your array, so it would be pretty expensive if the array is too big. But then you could cache that render and incur in that performance hit only once for every change of the source of your loop, but that goes pretty much beyond your issue here.

Viewing 1 replies (of 1 total)
  • The topic ‘How to check if at least one key of array is true?’ is closed to new replies.