View Single Post
  #2  
Old 10-09-2003, 06:21 AM
  B00MER's Avatar 
B00MER B00MER is offline
 

X-Guru
  
Join Date: Sep 2002
Location: Keller, TX (Cart-Lab.com)
Posts: 3,165
 

Default

...And if are running an older version of X-cart less than version 3.3.8:

Save the following code to Smarty-2.1.1/plugins/function.random.php.

Note your Smarty-2.1.1 directory may differ.

Code:
<? /* * Smarty plugin * ------------------------------------------------------------- * File: function.random.php * Type: function * Name: random * Author: Ben Godfrey <ben@hypothetical.co.uk> * Purpose: outputs a random number in the range specified by min and max attribs or 0 and mt_randmax * Usage: {random min=0 max=10}, {random min=-10}, {random max=20} or just {random} * ------------------------------------------------------------- */ function smarty_function_random($params, &$smarty) { extract($params); if (empty($min)) $min = 0; if (empty($max)) $max = mt_getrandmax(); // complain about erroneous args if (!is_numeric($min)) { $smarty->trigger_error("random: parameter 'min' must be a number"); return; } if (!is_numeric($max)) { $smarty->trigger_error("random: parameter 'max' must be a number"); return; } print(mt_rand(floor($min), ceil($max))); } // initialise random number sequence mt_srand(time()); ?>

How to use it in .tpls?

Code:
{random min=0 max=10}, {random min=-10}, {random max=20} or just {random}

Kudos!
__________________
Cart-Lab - 100+ Social Bookmarks for X-Cart.
Reply With Quote