London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!

How to dynamically display current year in a footer in episerver

Vote:
 

Hi,

I have a property 

public virtual XhtmlString FooterCopyRightText { get; set; }

Through CMS, editor will add the text with year in this. While rendering this property on View, I want to display the current year on it dynamically.

How to do it?

#226712
Aug 19, 2020 6:09
Vote:
 

Hi Tanvi,

I believe this proprty is to display like - (c) 2019. You can add a placeholder {0} from the CMS in the field value. Replace that placeholder with current year in Front end.


E.g 

So input would text for FooterCopyRightText will like '© {0}'
 string.Fromat(FooterCopyRightText.ToHtmlString(), DateTime.Today.Year); => (c) 2019.

Dipak 

#226714
Edited, Aug 19, 2020 6:25
Vote:
 

Dipak, can you give an example here properly, I'm not able to get it

#226720
Aug 19, 2020 11:04
Vote:
 

When you will set the value from the CMS set it with placeholder i.e. '{0}' 
In your case it would be like '@Copyright {0}', so that {0} is get replaced with current year on the front end or at controller. 

 string.Fromat(FooterCopyRightText.ToHtmlString(), DateTime.Today.Year);

O/p => @Copyright 2020

Also think about type of porpety, whether you want XHTMLString or string?   

#226734
Edited, Aug 19, 2020 12:54
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.