gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:37:56 26 4
gpt4 key购买 nike

我的代码如下:

内容.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 中有意设计的更改,但我找不到关于这些更改的任何文档。

不过,我真正想知道的是,实现上述功能的最佳方式是什么?

== 编辑 ==

我注意到即使从扩展ing 文件调用{$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.

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

来自聪明的开发者:

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

关于php - 从扩展模板调用时的 $smarty.current_dir 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35559402/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com