Symfony2: phpinfo () using a branch template for layout?

Twig will not process PHP tags. Therefore, creating a page phpinfo()based on layout (for example base.html.twig) is difficult.

Is it possible to upload HTML content phpinfo()to some kind of variable and pass it as body content to the layout? Or is there a better way to continue?

+4
source share
2 answers

Just write the output phpinfo()with output buffering and pass it to the template.

ob_start();
phpinfo();
$phpinfo = ob_get_clean();

echo $twig->render('phpinfo.html.twig', array('phpinfo' => $phpinfo));
+6
source

This is a complement to the answer from Federkun. In the controller:

ob_start();
phpinfo();
$phpinfo = ob_get_contents();
ob_end_clean();
return $this->render('phpinfo.html.twig', array(
    'phpinfo'=>$phpinfo,
));

Do not forget to put | raw in a twig!

{{ phpinfo | raw }}
0
source

Source: https://habr.com/ru/post/1610117/


All Articles