Is there a way to randomize an output with velocity
We currently have a quote that displays on our homepage that is setup with start and end dates. So once the quote expires the next quote takes it's place. We are finding that this doesn't change out as much as we would like. We would like to display a randomized quote from the set entered on the page. I know this can be done using javascript or php but is it possible in velocity? I would prefer to do this in velocity so only one quote is actually output rather than outputting all the quotes and then randomizing which displays with either php or javascript.
Discussions are closed to public comments.
If you need help with Cascade CMS please
start a new discussion.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
1 Posted by Ryan Griffith on 08 Jul, 2015 05:23 PM
Hi Thane,
You should be able to accomplish this by first obtaining an array of your quotes (eg using the XPath Tool) and then use the Math Tool's
random
method to generate a random number so you can access that index within your array.For example, consider the following pseudo code:
Please let me know if you have any questions.
Thanks!
Tim closed this discussion on 03 Aug, 2015 08:07 PM.