[英]Get directory name from path in Smarty only
I cannot assign my own PHP function.我无法分配我自己的 PHP function。 (I just have access to the TPL file).
(我只能访问 TPL 文件)。
So far I got {$smarty.server.PHP_SELF}
, which returns something like /foo/bar.xin
.到目前为止,我得到了
{$smarty.server.PHP_SELF}
,它返回类似/foo/bar.xin
的东西。 With built in functions, I'd like to get /foo/
.使用内置函数,我想获得
/foo/
。
{$smarty.server.PHP_SELF | dirname}
{$smarty.server.PHP_SELF | dirname}
will return /foo
assuming the dirname function is enabled (see php_modifiers
in Smarty security settings ). {$smarty.server.PHP_SELF | dirname}
将返回/foo
假设目录名 function 已启用(请参阅Smarty 安全设置中的php_modifiers
)。
As I noted, {php}
tags are deprecated, but you can do the following:正如我所指出的,
{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>
I haven't been able to test this, since I don't have a parser at my disposal, but it follows the example on the Smarty documentation page:我无法对此进行测试,因为我没有可用的解析器,但它遵循 Smarty 文档页面上的示例:
http://www.smarty.net/docs/en/language.function.php.tpl http://www.smarty.net/docs/en/language.function.php.tpl
{$smarty.server.DOCUMENT_ROOT}
will return server path将返回服务器路径
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.