Reputation: 6546
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())
);
});
Upvotes: 4
Views: 9007
Reputation: 30975
In you twig template you can do :
{% if weather.wind.deg is defined %}
make your things
{% endif %}
Upvotes: 7