print data to twig file from custom form submit via controller I have created a custom form, and I'm passing data to twig file from submitForm function as follows

public function submitForm(array &amp;$form, FormStateInterface $form_state)
{
$form_state-&gt;setRebuild();

$data = ['role' =&gt; $form_state-&gt;getValue('role'),
'date' =&gt; $form_state-&gt;getValue('date')
];
MyController::Detail($data);

}


and in controller passing data to twig 

public static function Detail($data) {

return [
'#theme' =&gt; 'my_report',
'#data' =&gt; $data,
];

}


but not able to get/print data in twig file.
When you set rebuild in a form submit there is no controller involved. The next page displayed is the rebuilt form, where you can print the my_report twig template by adding it to the build array $form.

You don't need to transfer the values in $form_state, because they are available while rebuilding the form. You can check in the form build function whether these values are present. If not, you are building a new form. If they are, this is a form rebuild, then display the result template:

  public function buildForm(array $form, FormStateInterface $form_state) {

    // build form

    if ($form_state-&gt;hasValue('role')) {
      $form['my_report'] = [
        '#theme' =&gt; 'my_report',
        '#role' =&gt; $form_state-&gt;getValue('role'),
      ];
    }
    return $form;
  }