So here's the situation I am trying to convert Dates and Times so I can use them in a Java Script within my Smarty Template File.

Here is the Snipet from my Template File:

<div class="containertable">
{foreach item=e from=$ads} {if $e.value}{if $e.field==e_10}
       {if $e.value == 'November'}
       {php}$date = "11";{/php}
       {php}echo "$date";{/php}
       {php}$newdate = "dateFuture = new Date(2007,$date,13,17,25,00);";{/php}       

 {literal} <script type="text/javascript">
<!-- //start

// format: dateFuture = new Date(year,month-1,day,hour,min,sec)\n'+
// example: dateFuture = new Date(2003,03,26,14,15,00) = April 26, 2003 - 2:15:00 pm\n\n'+
//Set Date Here
dateFuture = new Date(2007,11,13,17,25,00);

{$e.field==e_10} contains the Month Variable. I want the Dates to appear as numbers, so I used the If Statement and used November for testing purposes. So right now the number 11 does appear on the Page which is good. Except I need it to be a Part of the Java Script.

I replace the following from the Javascript:

dateFuture = new Date(2007,11,13,17,25,00);

With:

<? echo "$newdate"; ?>

That didn't work.

Any suggestions?? Or advise on a better way to go about this?

    code written inside {literal} won't work. Templates aren't included into your script, they are processed, so <?php ?> inside template won't execute. Try closing {/literal}, open {php}, echo the new date close {/php}, open {literal} again.
    But to do it in the spirit of Smarty, you should compute the values of data and newdate before you call the template, and pass the values to the template using ->assign();

      All right works like a charm..........its a little much in the Template File but it works.

      Here is my working Snipet:

      <div class="containertable">
      {foreach item=e from=$ads} {if $e.value}{if $e.field==e_10}
      
      {if $e.value == 'January'}
      	{php}$date = 1;$year = 2008;{/php}
      {elseif $e.value == 'February'}
      	{php}$date = 2;$year = 2008;{/php}
      {elseif $e.value == 'March'}
      	{php}$date = 3;$year = 2008;{/php}
      {elseif $e.value == 'April'}
      	{php}$date = 4;$year = 2008;{/php}
      {elseif $e.value == 'May'}
      	{php}$date = 5;$year = 2008;{/php}
      {elseif $e.value == 'June'}
      	{php}$date = 6;$year = 2008;{/php}
      {elseif $e.value == 'July'}
      	{php}$date = 7;$year = 2008;{/php}
      {elseif $e.value == 'August'}
      	{php}$date = 8;$year = 2008;{/php}
      {elseif $e.value == 'September'}
      	{php}$date = 9;$year = 2008;{/php}
      {elseif $e.value == 'October'}
      	{php}$date = 10;$year = 2007;{/php}
      {elseif $e.value == 'November'}
      	{php}$date = 11;$year = 2007;{/php}
      {elseif $e.value == 'December'}
      	{php}$date = 12;$year = 2007;{/php}
      {/if}{/if}{/if}{/foreach}               
      
       {literal} <script type="text/javascript">
      <!-- //start
      
      // format: dateFuture = new Date(year,month-1,day,hour,min,sec)\n'+
      // example: dateFuture = new Date(2003,03,26,14,15,00) = April 26, 2003 - 2:15:00 pm\n\n'+
      //Set Date Here
      dateFuture = new Date({/literal}{php}echo "$year";{/php}{literal},{/literal}{php}echo "$date";{/php}{literal},13,17,25,00);
      
      function GetCount(){
      
      dateNow = new Date();									//grab current date
      amount = dateFuture.getTime() - dateNow.getTime();		//calc milliseconds between dates
      delete dateNow;
      
      // time is already past
      if(amount < 0){
      	document.getElementById('countbox').innerHTML="Match Has Expired";
      }
      // date is still good
      else{
      	days=0;hours=0;mins=0;secs=0;out="";
      
      	amount = Math.floor(amount/1000);//kill the "milliseconds" so just secs
      
      	days=Math.floor(amount/86400);//days
      	amount=amount%86400;
      
      	hours=Math.floor(amount/3600);//hours
      	amount=amount%3600;
      
      	mins=Math.floor(amount/60);//minutes
      	amount=amount%60;
      
      	secs=Math.floor(amount);//seconds
      
      	if(days != 0){out += days +" day"+((days!=1)?"s":"")+", ";}
      	if(days != 0 || hours != 0){out += hours +" hour"+((hours!=1)?"s":"")+", ";}
      	if(days != 0 || hours != 0 || mins != 0){out += mins +" minute"+((mins!=1)?"s":"")+", ";}
      	out += secs +" seconds";
      	document.getElementById('countbox').innerHTML=out;
      
      	setTimeout("GetCount()", 1000);
      }
      }
      
      window.onload=function(){GetCount();}//call when everything has loaded
      
      //-->
      </script>{/literal}

      What I want to do is create a Second Countdown on the same Page. Can I just paste this script again right below this one?? I assume I would need to change some Variables?? Any idea how I can go about this?

        5 days later

        What I am trying to do now is print the Countdown mutiple times. Each time will have different values and a different count down.

        Basically what happens is Each item in my Database will be displayed. It will cycle through and Print information into tables. I would like to have the countdown as part of this information.

        Right now it will print the First Item's countdown only and will not print the other item's countdown.

        Here is a Screen Shot of what I am talking about:
        http://i88.photobucket.com/albums/k182/savj14/ss.jpg

        The countdown that is shown in the SS above is actually for the Match in that list, so it is not working correctly. What I want to do is have the correct countdown listed for each Match.

        I have attached my code..........Any thoughts?

          Write a Reply...