Try our conversational search powered by Generative AI!

How to dynamically display current year in a footer in episerver



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?

Aug 19, 2020 6:09

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.


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


Edited, Aug 19, 2020 6:25

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

Aug 19, 2020 11:04

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?   

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.