Passing an array stdClass Object from custom module to template 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' =&gt; 'webservices_client',
            '#id' =&gt; $infos_clients-&gt;body-&gt;id,
            '#nom' =&gt; $infos_clients-&gt;body-&gt;nom,
 ];


But when I receive that kind of array $response-&gt;body :

Array
(
    [0] =&gt; stdClass Object
        (
            [numero] =&gt; 625
            [dateDebut] =&gt; 2018-09-27T09:21:54.5746973
        )

    [1] =&gt; stdClass Object
        (
            [numero] =&gt; 468
            [dateDebut] =&gt; 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' =&gt; 'webservices_informations',
            '#myvariable' =&gt; $response,
       ];


in my-module.module :

function webservices_informations_theme(array $existing, $type, $theme, $path) {
    return array(
        'webservices_informations' =&gt; array(
            'variables' =&gt; array(
                'myvariable' =&gt; NULL,
            ),
        ),
    );
}


In twig template :

{% for key, value in myvariable %}
            Key : {{ key }}&lt;br&gt;
            Name : {{ value.id }}&lt;br&gt;
{% endfor %
I don't know why it was not working because after I've done a simple 

&lt;pre&gt;
    {{ dump(myvariable) }}
&lt;/pre&gt;


In order to check if the array was passed to the twig template, everything is working.

So the solution is in my-template.html.twig

{% for key, value in myvariable %}
    Key : {{ key }}&lt;br&gt;
    Date: {{ value.dateDebut }}&lt;br&gt;
    Societe : {{ value.societe }}&lt;br&gt;
{% endfor %}