linuxatico linuxatico - 2 months ago 20
PHP Question

how to make dompdf handle twig page

I have to convert a dynamic page written with TWIG to PDF. I am unable to make him interpret the TWIG code, every php, html output is rendered but TWIG is ignored. Can you tell me if there is a solution that is not "to rewrite the same template in php" ?


use the render function? it outputs html so that you can pass it in your DomPDF.

$twig = new Twig_Environment($loader, array(
'cache' => '/path/to/compilation_cache',
$dompdf->load_html($twig->render('index.html', array('name' => 'Fabien')));

If you are under Symfony

$dompdf->load_html($this->renderView('index.html', array('name' => 'Fabien')));