is there a way in Smarty to get the file extension of a string. I have been searching for the explode equivalent although can't seem to find anything.
I am wanting to display a different icon based on the type of file eg. doc,docx,pdf
is there a way in Smarty to get the file extension of a string. I have been searching for the explode equivalent although can't seem to find anything.
I am wanting to display a different icon based on the type of file eg. doc,docx,pdf
Since you can use php functions as modifiers, you can use the function pathinfo()
All php-functions can be used as modifiers implicitly, as demonstrated in the example above. However, using php-functions as modifiers has two little pitfalls:
First - sometimes the order of the function-parameters is not the desirable one. Formatting $foo with {"%2.f"|sprintf:$foo} actually works, but asks for the more intuitive, like {$foo|string_format:"%2.f"} that is provided by the Smarty distribution.
Secondly - if security is enabled, all php-functions that are to be used as modifiers have to be declared trusted in the $modifiers property of the securty policy. See the Security section for details. Source
<?php
$smarty->assign('filename', 'foo\bar.txt');
?>
{* template *}
{$filename|pathinfo:$smarty.const.PATHINFO_EXTENSION}
{* outputs 'txt' *}