Skip to content

Commit df4ca93

Browse files
committed
make _tex global var
1 parent 202cb45 commit df4ca93

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/LatexRenderer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public function renderPdf(string $templateName, array $variables, array $files =
123123
'template' => $templateName,
124124
],
125125
];
126-
$variables = array_merge($latexVars, $variables);
126+
$this->twig->addGlobal('_tex', $latexVars);
127127
$tex = $this->twig->render($templateName . '.tex.twig', $variables);
128128

129129
file_put_contents($this->tmpDir . "tex/$templateName/$uid/main.tex", $tex);

src/PdfFilterExtension.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Symfony\Component\Process\ExecutableFinder;
66
use Symfony\Component\Process\Process;
7+
use Twig\Error\RuntimeError;
78
use Twig\TwigFilter;
89

910
class PdfFilterExtension extends \Twig\Extension\AbstractExtension
@@ -27,13 +28,17 @@ public function getFilters(): array
2728
* @param array $context all variables
2829
* @param string $relFilePath only the filename, no path is needed. Directory is taken as _tex.dir/files/
2930
* @return int|null returns null if file does not exist, int with number of pages otherwise
31+
* @throws RuntimeError
3032
*/
3133
public function pages(array $context, $relFilePath): ?int
3234
{
35+
if (!isset($context['_tex']['dir'])) {
36+
throw new RuntimeError('_tex is not visible in this context');
37+
}
3338
$dir = $context['_tex']['dir'];
3439
$file = $dir . $relFilePath;
3540
if (!file_exists($file)) {
36-
return null;
41+
throw new RuntimeError('File does not exist');
3742
}
3843
if (!empty($this->qpdf)) {
3944
$p = new Process(['qpdf', '--show-npages', $file]);

0 commit comments

Comments
 (0)