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

Inserting php or javascript into pages

Discussion in 'XenForo Questions and Support' started by AndreaMarucci, Jun 6, 2011.

  1. AndreaMarucci

    AndreaMarucci Well-Known Member

    I've setup a page that display meteo forecast for the future days but I would like to put a simple date below every image with the date like "1 june 2011", "2 june 2011" and so on.

    I've tried to put a simple date string with php but does not work. How can I do that? Maybe with javascript? Any suggestion?

    Thanks!
     
  2. Brogan

    Brogan XenForo Moderator Staff Member

    You can use JavaScript directly in XenForo pages.

    To use PHP though you will need to do a PHP Callback.
     
  3. AndreaMarucci

    AndreaMarucci Well-Known Member

    Ok so I'll use Js since I don't really know what are PHP Callbacks :)
     
  4. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Here is template syntax to display the current date like you want:

    Code:
    {xen:date $serverTime, 'j F Y'}
    
    You can pass in a timestamp other than $serverTime if one is available to you.
     
  5. AndreaMarucci

    AndreaMarucci Well-Known Member

    Thanks Jake. Do you mean that I can insert this one in my page instead of the javascript? If positive, how can i add one day to the date to disaply tomorrow's date?
     
  6. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Yes, to display the current date you can use that code directly in the templates (or in page nodes).

    It's ugly, but it works:

    Code:
    {xen:date {xen:calc "{$serverTime} + 3*86400"}, 'j F Y'}
    
    This will add 3 days to the date. You can change the 3 to specify any number of days. (there are 86400 seconds in a day)
     
  7. AndreaMarucci

    AndreaMarucci Well-Known Member

    There must be something wrong. In my meteo page I've inserted that code
    Code:
    <table border="0" width="100%" cellpadding="2" cellspacing="2">
        <tr align="center">
            <td><img src="http://meteo.sky.it/meteo/images/italia/italia_0_18.png" alt="" border="0"></td>
            <td><img src="http://meteo.sky.it/meteo/images/italia/italia_1_18.png" alt="" border="0"></td>
        </tr>
        <tr align="center">
            <td>{xen:date $serverTime, 'j F Y'}</td>
            <td>{xen:date {xen:calc "{$serverTime} + 1*86400"}, 'j F Y'}</td>
        </tr>
        <tr align="center">
            <td><img src="http://meteo.sky.it/meteo/images/italia/italia_2_18.png" alt="" border="0"></td>
            <td><img src="http://meteo.sky.it/meteo/images/italia/italia_3_18.png" alt="" border="0"></td>
        </tr>
        <tr align="center">
            <td><script type="text/javascript">
    <!--
    var currentTime = new Date()
    var month = currentTime.getMonth() + 1
    var day = currentTime.getDate() +2
    var year = currentTime.getFullYear()
    document.write(day + "/" + month + "/" + year)
    //-->
    </script></td>
            <td><script type="text/javascript">
    <!--
    var currentTime = new Date()
    var month = currentTime.getMonth() + 1
    var day = currentTime.getDate() +3
    var year = currentTime.getFullYear()
    document.write(day + "/" + month + "/" + year)
    //-->
    </script></td>
        </tr>
    </table>
    
    The two javascript works but the two xen:date I've inserted simply display as "{xen:date $serverTime, 'j F Y'}" just if they're not parsed...
     
  8. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Where exactly are you using that code? It works in the templates:

    Admin CP -> Appearance -> Templates

    And in page nodes:

    Admin CP -> Applications -> Create New Page -> Template HTML
     
  9. AndreaMarucci

    AndreaMarucci Well-Known Member

    Well I'm an idiot :( I've put all the code into the description area. Sorry for that. It works perfectly. Thank you very very much!!!
     

Share This Page