I want to create a PDF with DOMPdf. My PDF Template is located in
themes/Template/
themes/Template/templates
themes/Template/templates/Pdf
themes/Template/templates/Layout
But I receive a template not found error.
According to this Question silverstripe Sitetree onAfterWrite - renderWith Error: Template not found I put the template into mysite/templates/Pdf and it works.
Is there a way to keep the template in the theme folder?
Here's my code.
public function createPdf(){
$pdf = new SS_DOMPDF();
$data = array(
);
$pdf->setHTML($this->customise($data)->renderWith('InvOffPdf'));
$pdf->render();
$pdfFilename = str_replace(array(' ', '#'), '', $this->Title) . '.pdf';
$pdfFolder = 'clientcenter/' . $this->Client()->CID . '-' . $this->Client()->Random;
$pdf->toFile($pdfFilename, $pdfFolder);
$filename = 'assets/' . $pdfFolder . '/' . $pdfFilename;
$file = File::get()->Filter('Filename', $filename)->First();
if( $file ){
$file->ClientID = $this->ClientID;
$file->ShowInSearch = 0;
$file->write();
$this->Download = '<a href="' . $filename . '">PDF herunterladen</a>';
$this->write();
}
}
edit: I've tried spekulatius' solution. but I've done something wrong.
$pdfTemplate = SSViewer::setTemplateFile('Layout', 'InvOffPdf');
$pdf->setHTML($this->customise($data)->renderWith($pdfTemplate));
This is the error I receive
[Strict Notice] Non-static method SSViewer::setTemplateFile() should not be called statically, assuming $this from incompatible context
What's the correct syntax?
Templateis the active theme?renderWithwill only look in the theme folder that's currently the active one. - bummzack