How to define a variable with random values ​​in Smarty

I need to assign a variable that will be used to create an identifier label for some html elements.

And it must be unique.

I tried

{assign var=unique_id value=`10|mt_rand:20`} 

and

 {math equation='rand(10,100)'} 

But I do not know how to use the result

I have no other ideas

+7
html smarty
source share
2 answers

this is how you set and use a random value, but does not mean that it will be unique.

  {assign var=unique_id value=10|mt_rand:20} {$unique_id} 

can you describe the big picture of what you are doing?

+20
source share

I wrote a little Smarty plugin a few years ago: https://www.markus.zierhut.name/2010/05/21/php-mit-smarty-zufallszahl-erzeugen/

This is a bit easier to use than handling mt_rand inside an assign function. And it maintains compatibility with the model and view section.

0
source share

All Articles