I needed a random tag and couldn't find the tag in forum. So I wrote it my own.
Put the following code to 'couch/addons/k_functions.php':
min is 0 and max is 10 by default. The use is simple:
Put the following code to 'couch/addons/k_functions.php':
- Code: Select all
$FUNCS->register_tag('rand', function($params, $node){
global $FUNCS;
// Extract parameters and set default values
$parameters = $FUNCS->get_named_vars(
array(
'min' => 0,
'max' => 10
),
$params
);
extract($parameters);
// Ensure min and max are integers
$min = intval($min);
$max = intval($max);
// Ensure max is greater than min
if($max <= $min) {
$max = $min + 10;
}
// Return random number between min and max
return rand($min, $max);
});
min is 0 and max is 10 by default. The use is simple:
- Code: Select all
Random dice: <cms:rand min="1" max="6" />
Random avatar: <img src="https://i.pravatar.cc/150?img=<cms:rand min='1' max='70' />">