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.
Thanks,
-Thom
llvdl
2
Have you tried {% if middle_slot['ad_type'] == 'label' %}
?
Yes I tried that too!
I even tried a twig switch case statement. Same issue.
llvdl
4
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.
index.php
$app->get('/', function($request, $response, $args) {
$middle_slot['ad_type'] = '1234';
return $this->view->render($response, 'test.html.twig', [
'middle_slot' => $middle_slot
]);
});
test.html.twig
<p>{{ middle_slot|keys|join(',') }}</p>
<p>{{ middle_slot.ad_type }}</p>
<p>{{ middle_slot['ad_type'] }}</p>