[英]Twig template cache with if condition
我有一个看起来像这样的模板
...
{% if whatever %}
<div>whatever<div>
{% endif %}
...
我这样设置环境
$twig = new \Twig_Environment(
new \Twig_Loader_Filesystem(
/template/path/
['cache' => '/cache/path/']
)
);
$whatever = someFunctionFetchingFromDatabase();
$twig->addGlobal('whatever', $whatever);
$twig->render('whatever');
$ whatever变量更改时,编译缓存是否会重置? 如果正在重置,那么当模板内的变量发生很大变化时,编译缓存的意义何在?
谢谢您的回答。
我发现编译的树枝变成了php文件,因此所有变量和if都保存在编译的php文件中。 使用带变量的编译很好,并且不会在每次变量更改时重新编译。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.