Inserting php or javascript into pages

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!
 
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.
 
Thanks Jake. Do you mean that I can insert this one in my page instead of the javascript?

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

If positive, how can i add one day to the date to disaply tomorrow's date?

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)
 
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...
 
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
 
Top Bottom