i have my view in twig
and i have an array which has or hasnt key value i need how to check it if its exist ?
example {{ weather.wind.deg }}
and for current moment its possible there is no wind deg so the weather.wind array will not contain an element witch key deg
how to check it if it has it or no ?
maybe i should do it before i past this to my view ?
somewhere here ?
$app->get('/', function () use ($app) {
return $app['twig']->render('index.html.twig', array(
'weather' => $app['weather_service']->get($app['location_service']->get()),
'location' => $app['location_service']->get())
);
});
In you twig template you can do :
{% if weather.wind.deg is defined %}
make your things
{% endif %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With