从扩展模板调用时$ smarty.current_dir值

时间:2016-02-22 16:57:22

标签: php smarty smarty3

我的代码如下:

content.tpl:

{* Smarty *} 
{extends file='PageContentLayout.tpl'}

PageContentLayout.tpl

{* Smarty *} 
{block name="file_name"}
    <p>{$smarty.current_dir}</p>
    <p>{$smarty.template}</p>
{/block}


{block name="other_content"} 
    ... 
    {* blah... *} 
    ... 
{/block} 

在早期版本的smarty中,此代码将打印文件的模板名称和路径:content.tpl

但是,我刚刚升级到3.1.29,现在它似乎是正在打印的基本文件PageContentLayout.tpl的名称。

我认为这是Smarty的不同版本中的故意设计更改,但我无法找到有关这些更改的任何文档。

我真正想知道的是,实现前一功能的最佳方法是什么?

==编辑==

我注意到即使从extend ing 文件中调用{$smarty.current_dir},我们仍然会获得基本文件的路径和文件名。这是与早期版本相比的一个重大变化,在我的情况下非常严重,因为我无法编写动态代码来查找顶级文件的路径。

1 个答案:

答案 0 :(得分:4)

这可能是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.

这确实解决了所有已知的现有限制(见下文)。

来自聪明的开发者:

版本&lt; 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是否没有您需要的数据。