Jump to content

Add: Date/Time Variable to tpl file


gdinari

Recommended Posts

Hi, I wanted to add a date/time stamp in the footer tpl of my theme.

 

I added the desire php code in the override FrontController.php for the footer function, but when I load the page the code comes up empty.

 

Here is my code:

 

override/classes/controllers/FrontController.php

 

 

class FrontController extends FrontControllerCore
{

function displayFooter()
{
// This method will be removed in 1.6
$today = date("F j, Y, g:i a");
self::$smarty->assign( 'date_time', $today );
}

}

 

...then in my footer.tpl I add my new variable:

 

{$today}

 

 

Cache is not enabled and I dont know what the problem.

 

Can someone please help with this?

 

 

 

Thank you

Link to comment
Share on other sites

Instead of using php I decided that javascript would be easier. So for anyone looking for a solution I used this instead:

 

 

<SCRIPT language="JavaScript" type="text/javascript">
               <!--
               // current date - from http://rainbow.arch.scriptmania.com/scripts
               // Array of day names
               var dayNames = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");

               var monthNames = new Array("January","February","March","April","May","June","July",
                                          "August","September","October","November","December");

               var dt = new Date();
               var y  = dt.getYear();

               // Y2K compliant
               if (y < 1000) y +=1900;

               document.write(dayNames[dt.getDay()] + " " + monthNames[dt.getMonth()] + " " + dt.getDate() + ", " + y);
               // -->
               </SCRIPT>

  • Like 1
Link to comment
Share on other sites

  • 1 year later...

You could just add this line to the themes/<your theme folder>/footer.tpl:

 

{$smarty.now|date_format:"%A, %B %e, %Y"}
 
Like here: (Sample code from PS 1.5.6.2):
 
<!-- Footer -->
			<div id="footer" class="grid_9 alpha omega clearfix">
				{$HOOK_FOOTER}
				{if $PS_ALLOW_MOBILE_DEVICE}
					<p class="center clearBoth"><a href="{$link->getPageLink('index', true)}?mobile_theme_ok">{l s='Browse the mobile site'}</a></p>
				{/if}

				{$smarty.now|date_format:"%A, %B %e, %Y"}

			</div>
		</div>

 
 
Hope this helps,
pascal.
Edited by PascalVG
link to smarty function documentation added: (see edit history)
  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...