car*_*rse 5 php smarty smarty3
我的代码如下:
content.tpl:
{* Smarty *}
{extends file='PageContentLayout.tpl'}
Run Code Online (Sandbox Code Playgroud)
PageContentLayout.tpl
{* Smarty *}
{block name="file_name"}
<p>{$smarty.current_dir}</p>
<p>{$smarty.template}</p>
{/block}
{block name="other_content"}
...
{* blah... *}
...
{/block}
Run Code Online (Sandbox Code Playgroud)
在早期版本的smarty中,此代码将打印模板名称和文件路径:content.tpl.
但是,我刚刚升级到3.1.29,现在看来它PageContentLayout.tpl是正在打印的基本文件的名称.
我认为这是Smarty的不同版本中的故意设计更改,但我找不到有关这些更改的任何文档.
我真正想知道的是,实现前一功能的最佳方法是什么?
==编辑==
我注意到,调用,即使{$smarty.current_dir}从延长荷兰国际集团的文件,我们仍然得到基本文件的路径和文件名.这是与早期版本相比的一个重大变化,在我的情况下非常严重,因为我不能再编写动态代码来查找顶级文件的路径.
这可能是 smarty 最新变化的结果
Starting with version 3.1.28 template inheritance is no longer a compile time process.
All {block} tag parent/child relations are resolved at run time.
Run Code Online (Sandbox Code Playgroud)
这确实解决了所有已知的现有限制(见下文)。
来自聪明的开发人员:
版本 <3.1.28确实缓存了所有模板对象以提高性能,以便在多次调用子模板的情况下重用它们。然而,这浪费了记忆。3.1.28 针对大小和速度进行了优化,内部模板对象处理完全不同。已$smarty->template_objects被删除。
启用调试后,可以在数组中找到一些信息,例如模板文件路径$smarty->_debug->template_data。
继承发行说明:https://github.com/smarty-php/smarty/blob/master/INHERITANCE_RELEASE_NOTES.txt
新功能:https://github.com/smarty-php/smarty/blob/master/NEW_FEATURES.txt
您可以检查是否$smarty.template_object没有您需要的数据。