开发者

Perform the MD5 function in Smarty Template Engine

开发者 https://www.devze.com 2023-04-11 03:55 出处:网络
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

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!


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


This might work. Haven't tested:

{assign var="string_to_hash" value="$string:$salt"}
{$string_to_hash|md5}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号