2012-09-24 70 views
1

我必須將用TWIG寫入的動態頁面轉換爲PDF。我無法讓他解釋TWIG代碼,每個php,html輸出都被渲染,但是TWIG被忽略。你能告訴我,如果有一種解決方案不是「在PHP中重寫相同的模板」嗎?如何使dompdf處理樹枝頁面

回答

3

使用渲染功能?它會輸出html,以便您可以將它傳遞到您的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"); 

如果你的Symfony

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