我试图渲染出没有布局,只有几个变量和一些循环的小枝模板。渲染小枝模板返回“缓存已损坏”并输出PHP代码
当我呼吁嫩枝的render()
功能,它输出的PHP代码块下面的类:
php
/** path/to/my/template.html.twig */
class __TwigTemplate_435244378aba3a3f94258b7d2af4d53eb7a41acb741dd3ad0efcac038b621c67 extends Twig_Template
{
// bunch of methods for Twig_Template,
// including the compiled version of my template
}
在此之后它给我下面的异常堆栈跟踪:
未能加载Twig模板“path/to/my/template.html.twig”,索引“”:缓存在“path/to/my/template.html.twig”中损坏。
我甚至没有使用此应用程序缓存目前,虽然增加一个缓存似乎没有做出不同。我使用的树枝像这样:
// Factory to return a new Twig environment
$loader = new \Twig_Loader_Filesystem(__DIR__ . '/../../views/');
return new \Twig_Environment($loader);
// My class has $this->twig set to the above object
$this->twig->render('path/to/my/template.html.twig', [
'report' => $report,
'file' => $file
]);
枝条似乎能在我的模板阅读,作为PHP代码在错误输出块具有模板的正确编译版本。试图设置可写的缓存目录仍然会导致相同的错误。
我在Apache下使用Twig 1.34.4和PHP 5.6.29。
编辑
成功的一点,在某种程度上。似乎Twig永远不会评估它生成的代码。
我编辑的供应商/树枝/树枝/ lib中/嫩枝/ Environment.php文件和行448增加了以下内容:
eval("?><?" . $content);
,我的模板处理就好了。这使我得出了Twig的其他结论正在打破的结论,但这不是一个长期的解决方案,因为我不应该编辑供应商文件。
从456行开始的块似乎表明$content
应该有开头<?
但我的没有。所以这可能会导致编译错误。
更多挖掘的时间。