I cannot assign my own PHP function. (I just have access to the TPL file).
So far I got {$smarty.server.PHP_SELF}
, which returns someth开发者_JS百科ing like /foo/bar.xin
. With built in functions, I'd like to get /foo/
.
As I noted, {php}
tags are deprecated, but you can do the following:
{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:
http://www.smarty.net/docs/en/language.function.php.tpl
{$smarty.server.PHP_SELF | dirname}
will return /foo
assuming the dirname function is enabled (see php_modifiers
in Smarty security settings).
{$smarty.server.DOCUMENT_ROOT}
will return server path
精彩评论