Hello,

I have migrating old reportin system to drupal 8. I have exist site where is report pages which I want to migrate to drupal. All report pages are kind of custom reports. Each php file ganerete spesific report. PHP script get data from mysql database and generate report data from raw data. Then report is showed using php, javascript and html compination.

I have tested drupal twig templates to show external page. It worked fine with javascript libraries but php is not supported in twig templates. How can I use exist php functions which generate report data and pass the report data to page where result is showed using javascript.

I use Controller to show my twig template and I know that I can use php in controller function. It could pass values like test_var to twig template but it not sound reasonable to pass hundreds values to template using that method.

class ReportController extends ControllerBase {
  public function content() {
    return array(
      '#theme' => 'report',
      '#test_var' => $this->t('Test Value'),
    );
  }
}

I would be very glad if someone could help me with the problem.

Comments

geek.geek’s picture

Hi,

You need to do the PHP in the *.theme.inc file and send the output to TWIG, that's how it works now.