is it possibble to generete random value in jquery templates ?
I using jqurey templates with expressjs and node.js and i'm trying generate some "dynamic" position elements on page. So i trying generete a random number in jqtpl and using it in inline css in layouts.
If I understand correctly, you could for example use hat. Especially the rack
function.
Call rack() repeatedly to generate new IDs which are checked for collisions.
code
var hat = require('hat');
var rack = hat.rack(9, 10);
console.log(rack());
console.log(rack());
output
$ node test.js
109
461
The following will work. The routing is an example and for reference https://github.com/kof/node-jqtpl/
Node:
app.get('/randomtest', function(req, res){
res.render('random.html',
{rnd: function(min, max) {
return Math.random() * (max - min) + min;
}
});
});
Template:
${rnd(1,10)}
The min/max control what gets outputted.