I’ve created some D8 custom modules which call rest API and and it’s working fine when I get simple array in my $response
.
In my controller, this is working :
return [
'#theme' => 'webservices_client',
'#id' => $infos_clients->body->id,
'#nom' => $infos_clients->body->nom,
];
But when I receive that kind of array $response->body
:
Array
(
[0] => stdClass Object
(
[numero] => 625
[dateDebut] => 2018-09-27T09:21:54.5746973
)
[1] => stdClass Object
(
[numero] => 468
[dateDebut] => 2018-05-17T16:50:33.6357383
)
)
I don’t how to send my array from the controller to the twig template and assign variable in my-module.module
Could you explain how to this ?
I've tried this kind of thing :
in controller :
return [
'#theme' => 'webservices_informations',
'#myvariable' => $response,
];
in my-module.module :
function webservices_informations_theme(array $existing, $type, $theme, $path) {
return array(
'webservices_informations' => array(
'variables' => array(
'myvariable' => NULL,
),
),
);
}
In twig template :
{% for key, value in myvariable %}
Key : {{ key }}<br>
Name : {{ value.id }}<br>
{% endfor %