Does Slim Twig 2.2 implementation support equality check of key value on arrays?

Such as {% if myobject.element == ‘label’ %} ? I keep getting key does not exist even though its there. Here’s the code for more clarity

{% if middle_slot.ad_type == ‘label’ %}

 {% include 'ad-pin-label-text-view.html.twig' with middle_slot %}

{% endif %}

complains about ad_type key does not exist.


Have you tried {% if middle_slot['ad_type'] == 'label' %}?

Yes I tried that too! :frowning: I even tried a twig switch case statement. Same issue.

Have you also tried {{ dump(middle_slot) }}? That should show you the value of middle_slot.

Edit: sorry, dump is not included in slim/php-view. {{ middle_slot|keys|join('.') }} should show you the keys in the array.

I have created a minimal app using slim/twig-view and the value if shown using both the dot notation and the array index notation.


$app->get('/', function($request, $response, $args) {
    $middle_slot['ad_type'] = '1234';

    return $this->view->render($response, 'test.html.twig', [
        'middle_slot' => $middle_slot


<p>{{ middle_slot|keys|join(',') }}</p>
<p>{{ middle_slot.ad_type }}</p>
<p>{{ middle_slot['ad_type'] }}</p>