我无法分配自己的PHP函数(我只能访问TPL文件)。
到目前为止,我得到了{$smarty.server.PHP_SELF}
,它返回类似于/foo/bar.xin
的内容。使用内置函数,我希望获得/foo/
。
正如我所指出的,{php}
标签是不推荐使用的,但您可以执行以下操作:
{php}
$php_self = $_SERVER['PHP_SELF'];
$path = substr($php_self, 0, strrpos($php_self, '/'));
// assign a variable to Smarty
$this->assign('path',$path);
{/php}
Path: <strong>{$path}</strong>
我还没能测试这个,因为我没有解析器,但它遵循了Smarty文档页面上的示例:
http://www.smarty.net/docs/en/language.function.php.tpl
{$smarty.server.PHP_SELF | dirname}
将返回/foo
,前提是dirname函数已启用(请参阅Smarty安全设置中的php_modifiers
)。
{$smarty.server.DOCUMENT_ROOT}
将返回服务器路径