php
Smarty Randomization
Smarty templating is great. But how do you get a random number? The answer is more simple than you think.
The smarty manual explains that most string arguments work. For instance try making a lower case string have upper case words with the php function ucwords:
{'php and smarty rock'|ucwords}
The output will be:
Php And Smarty Rock
According to the smarty manual, all php-functions can be used as modifiers implicitly. Still, what is really stunning is that rand works! Thanks to Great Britain for this piece of simple magic!
{0|rand:100} // generates a number between 0 and 100
The runner up for producing a random number is roblogic. Although, it is not recommended to create a plugin unless it is for the only web site you work on. Invariably, the plugin will not be in the next version of Smarty that you use.
Happy Randomization!
Last Updated: 2008-11-05 17:49:01