Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perform the MD5 function in Smarty Template Engine

In a Smarty templated theme I would like to implement MD5 within the template to get a unique hash based on a string and a salt. (Do not have access to the PHP calling the template, or this would be trivial). Smarty does not seem to have an MD5 function built into it. I thought I might be able to create a hash based on the length of the string and some other unique account information and by using Smarty's Math function, but was hoping there might be a better way to do this that I'm overlooking. Anyone have any thoughts or ideas on this? Thank you!

like image 497
Dave Drager Avatar asked Oct 05 '11 15:10

Dave Drager


1 Answers

If you're just using the stock md5 function, you can use it as a modifier.

{$string|md5}

From documentation:

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 MODIFIER_FUNCS element of the $security_settings array.

Source v2
Source v3

like image 130
Paul DelRe Avatar answered Nov 06 '22 16:11

Paul DelRe