Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Templates Smarty子模板块在更新时会断开_Templates_Include_Block_Template Engine_Smarty3 - Fatal编程技术网

Templates Smarty子模板块在更新时会断开

Templates Smarty子模板块在更新时会断开,templates,include,block,template-engine,smarty3,Templates,Include,Block,Template Engine,Smarty3,我正在尝试使用Smarty for php创建一个模板。我希望模板是可重用的,所以我继承它并使用块替换值。除非我需要在子模板中访问这些块值,否则这可以正常工作。我使用smarty的{include}函数调用这些子模板 例如: 模板父级(Template.tpl): 当我查看站点时,输出为: <html> <head> <title>No Title Provided</title> </head>

我正在尝试使用Smarty for php创建一个模板。我希望模板是可重用的,所以我继承它并使用块替换值。除非我需要在子模板中访问这些块值,否则这可以正常工作。我使用smarty的{include}函数调用这些子模板

例如:

模板父级(Template.tpl):

当我查看站点时,输出为:

<html>
     <head>
         <title>No Title Provided</title>
     </head>

     <body>
         My Website!
     </body>
</html>

没有提供标题
我的网站!
在做了一些研究之后,我确实在smarty的网站上看到了一条关于将{include}函数封装在伪{block}标记中的注释,但在实现这一功能方面取得了不同程度的成功

注: 如果有一个子模板包含在{include}中 包含{block}区域只有在{include}本身为 从周围的{block}中调用。在最后一个家长 模板您可能需要一个虚拟的{block}(http://www.smarty.net/docs/en/advanced.features.template.inheritance.tpl)

因此,我尝试:

<html>
     <head>
         {block name=dummy}{include file=sub_template.tpl}{/block}
     </head>

     <body>
         {block name=title}No Title Provided{/block}
     </body>
</html>

{block name=dummy}{include file=sub_template.tpl}{/block}
{block name=title}未提供标题{/block}
在我对子模板进行任何更改之前,这似乎是有效的。对子模板进行更改后,它将再次停止响应子模板中设置的块值

我是否误解了通知中关于将{include}放置在虚拟块标记中的内容,或者这是smarty的一个bug?我目前没有使用缓存,但我的另一个想法是,这可能是一个子模板缓存问题


如有任何见解,将不胜感激,谢谢

这些模板确实被编译并缓存到templates目录中。这就是为什么清除templates目录暂时解决了这个问题。模板缓存不同于smarty也支持的显式缓存。我发现模板缓存可以通过以下方式覆盖:

$smarty->compile_check = true;
$smarty->force_compile = true;

这允许对模板进行更改,而无需在开发过程中删除更改后的缓存

我认为这实际上可能是一个缓存问题。我清除了smarty目录中的“templates_c”文件夹,这会使块值在sub_模板文件中按预期工作。但是,一旦更改了sub_模板,它将再次停止在块中查找值。是否有一种优雅的解决方案不涉及每次更改后手动清除缓存?
<html>
     <head>
         <title>No Title Provided</title>
     </head>

     <body>
         My Website!
     </body>
</html>
<html>
     <head>
         {block name=dummy}{include file=sub_template.tpl}{/block}
     </head>

     <body>
         {block name=title}No Title Provided{/block}
     </body>
</html>
$smarty->compile_check = true;
$smarty->force_compile = true;