how to make dompdf handle twig page

自闭症网瘾萝莉.ら 提交于 2019-12-24 16:44:08

问题


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" ?


回答1:


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')));
$dompdf->render(); 
$dompdf->stream("sample.pdf");

If you are under Symfony

$dompdf->load_html($this->renderView('index.html', array('name' => 'Fabien')));
$dompdf->render(); 
$dompdf->stream("sample.pdf");


来源:https://stackoverflow.com/questions/12561250/how-to-make-dompdf-handle-twig-page

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!