How to check if record exist in respons TWIG - data in table format

Viewed 233

I have a multidimensional array where some objects exist and others don't. The whole data has used in page. Then I plan check it in TWIG. example data:

array:2[
  0 => Data1 {
    -id: 17
    -porodType: "1d"
    -name: "Dally promotion" 
  }
  1 => Data1 {
    -id: 34
    -porodType: "S"
    -name: "Special" 
  }    
]

How to check if record with porodType = "1d" exist in respons? How to display different message for this acction: exist(OK)/no-exist(ERROR)?

When check in TWIG:

{% for d in Data1 %}
    {% if d.porodType == '1d' %}
        <button class="btn">OK</button>
    {% else %}
        <button class="btn"">Error</button>
    {% endif %}
{% endfor %}

this code result is: <button class="btn">OK</button><button class="btn">Error</button>

but I expected <button class="btn">OK</button> or <button class="btn">ERROR</button>

2 Answers
Related