Lazlo
Lazlo

Reputation: 8790

Get directory name from path in Smarty only

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 something like /foo/bar.xin. With built in functions, I'd like to get /foo/.

Upvotes: 0

Views: 1960

Answers (3)

Jethik
Jethik

Reputation: 1876

{$smarty.server.DOCUMENT_ROOT}  

will return server path

Upvotes: 0

Tgr
Tgr

Reputation: 28210

{$smarty.server.PHP_SELF | dirname} will return /foo assuming the dirname function is enabled (see php_modifiers in Smarty security settings).

Upvotes: 1

Jared Farrish
Jared Farrish

Reputation: 49238

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

Upvotes: 1

Related Questions