1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Random header-image

Discussion in 'XenForo Questions and Support' started by bart, Mar 14, 2013.

  1. bart

    bart Active Member

    Is it possible to generate a random number in a template?

    I need a number between 1 and 10 like in rand(1,10) to add to the header-image-url (in the header-template or in the header-css). Can it be done through javascript maybe?

    What would be a good way to do it?
  2. Brogan

    Brogan XenForo Moderator Staff Member

  3. bart

    bart Active Member

    That works!

    As for me, to get a random image out of seven I use:

    <xen:if is="!{$rand}">
    <xen:set var="$rand">{xen:calc '({$serverTime} % 7) + 1'}</xen:set>

    <div id="header" style="background:http://..../images/header_{$rand}.jpg)">

  4. kankan

    kankan Active Member

    In the same way i am looking for a way to generate a random background.
    Any trick to perform this ?
    Thank you
  5. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    bart likes this.

Share This Page