nVelocity for current YEAR?

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
User avatar
NC Software
AbleCommerce Partner
AbleCommerce Partner
Posts: 4620
Joined: Mon Sep 13, 2004 6:06 pm
Contact:

nVelocity for current YEAR?

Post by NC Software » Fri May 29, 2009 12:21 pm

In my footer I'd like to have the Copyright YEAR value automatically set so I never have to touch it again. Can this be done using nVelocity?
Neal Culiner
NC Software, Inc.

User avatar
Logan Rhodehamel
Developer
Developer
Posts: 4116
Joined: Wed Dec 10, 2003 5:26 pm

Re: nVelocity for current YEAR?

Post by Logan Rhodehamel » Fri May 29, 2009 12:34 pm

This would be roundabout, but $User.LastActivityDate.Year would probably do it. The LastActivityDate is always set for the user with the date the request was initiated. So long as your server time is correct, that will show the current year.
Cheers,
Logan
Image.com

If I do not respond to an unsolicited private message, it's not because I'm ignoring you. It's because the answer to your question is valuable to others. Try the new topic button.

mihkeltt
Ensign (ENS)
Ensign (ENS)
Posts: 2
Joined: Mon Jun 15, 2009 8:41 am

Re: nVelocity for current YEAR?

Post by mihkeltt » Fri Jun 19, 2009 4:26 am

A bit more elegant solution would be to add

Code: Select all

DateTime.Now()
into the Page.Items dictionary which you have access from the template as

Code: Select all

$page.Items.get_Item("currentDate").Year
. Bear in mind that the date should be inserted into the items collection very early on in the page lifecycle. One point for this would be in global.asax in the

Code: Select all

Application_PreRequestHandlerExecute
event. The current page can be accessed there via

Code: Select all

HttpContext.Current.Handler as Page
.

Mihkel

kastnerd
Commodore (COMO)
Commodore (COMO)
Posts: 474
Joined: Wed Oct 22, 2008 9:17 am

Re: nVelocity for current YEAR?

Post by kastnerd » Fri Jun 19, 2009 6:25 am

I like this

Post Reply