Page 1 of 1

values are not displaying when passed to template

Posted: Thu Oct 18, 2007 2:19 am
by shivam0101
Everah | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  Posting Code in the Forums to learn how to do it too.[/color]


This is the code for displaying server time
[syntax="javascript"]
<script type="text/javascript">

// Current Server Time script (SSI or PHP)- By JavaScriptKit.com (http://www.javascriptkit.com)
// For this and over 400+ free scripts, visit JavaScript Kit- http://www.javascriptkit.com/
// This notice must stay intact for use.

//Depending on whether your page supports SSI (.shtml) or PHP (.php), UNCOMMENT the line below your page supports and COMMENT the one it does not:
//Default is that SSI method is uncommented, and PHP is commented:

var currenttime = '<? print date("F d, Y H:i:s", time())?>' //PHP method of getting server date

///////////Stop editting here/////////////////////////////////

var montharray=new Array("January","February","March","April","May","June","July","August","September","October","November","December")
var serverdate=new Date(currenttime)

function padlength(what){
var output=(what.toString().length==1)? "0"+what : what
return output
}

function displaytime(){
serverdate.setSeconds(serverdate.getSeconds()+1)
var datestring=montharray[serverdate.getMonth()]+" "+padlength(serverdate.getDate())+", "+serverdate.getFullYear()
var timestring=padlength(serverdate.getHours())+":"+padlength(serverdate.getMinutes())+":"+padlength(serverdate.getSeconds())
document.getElementById("servertime").innerHTML=datestring+" "+timestring
}

window.onload=function(){
setInterval("displaytime()", 1000)
}

</script>
if i echo like,[/syntax]

Code: Select all

$time="<table><tr><td><span id='servertime'></td></tr></table>";

echo $time;
// it works fine


but, if i try to pass $time to template its not working.


Everah | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  Posting Code in the Forums to learn how to do it too.[/color]

Posted: Thu Oct 18, 2007 7:55 am
by Zoxive
How are you `passing` it to the template, all i see is some JavaScript, and 2 lines of php.

Posted: Thu Oct 18, 2007 8:01 am
by s.dot
You're missing the </span>.. invalid HTML might be causing a problem.

Also, as noted above, are you assigning to the template? How are you calling it in the template?

Code: Select all

//something like this anywhere?
$tpl->assign('time', $time);

Posted: Thu Oct 18, 2007 9:32 am
by thewebdrivers
i strongly believe that you are simply adding the variable to the template and reading and printing contents of files. use eval instead of echo and i think it will work.

Posted: Thu Oct 18, 2007 10:21 am
by s.dot
No, please don't use eval() for something like that. :P

Posted: Thu Oct 18, 2007 11:35 am
by RobertGonzalez
So how are you getting the actual date into the Javascript code.

Posted: Fri Oct 19, 2007 3:01 am
by shivam0101
Thanks for your replies

i got it working, i made a mistake of not using '' when i am passing the values.