How to get dynamic current year in html page in kentico

ANKUR SHARMA asked on October 29, 2021 14:38

How to get current year in html page in kentico, in C# we use @DateTime.Now.Year but in kentico what we use ?

Recent Answers


David te Kloese answered on October 29, 2021 14:52

Where are you rendering it?

I assume you're using Portal Engine, you can just use macro's (does need a place that does the resolving. e.g. a Web Part like Rich Text, repeater, or any other that you use at that point)...

Macro itself would be something like: {% DateTime.Now.Year #%}

0 votesVote for this answer Mark as a Correct answer

ANKUR SHARMA answered on October 29, 2021 15:07

Copyright © {% DateTime.Now.Year #%} ABC Company, All rights reserved.

Copyright © {% DateTime.Now.Year #%} ABC® Tire & Company, All rights reserved.

This is a html page using Rich Text, but is not getting current year.

0 votesVote for this answer Mark as a Correct answer

David te Kloese answered on October 29, 2021 15:17

The web part or text fields needs to have resolve macro's enabled. Check the Web Part settings...

0 votesVote for this answer Mark as a Correct answer

ANKUR SHARMA answered on November 1, 2021 11:27

I am new in kentico, can you please tell me from where i can enable macro

0 votesVote for this answer Mark as a Correct answer

David te Kloese answered on November 1, 2021 15:22

ok first let's confirm what version and development method (Portal Engine/MVC/.Net Core) you're using?

As you might not be able to use macro's in the first place.

0 votesVote for this answer Mark as a Correct answer

ANKUR SHARMA answered on November 1, 2021 16:03

I am using Kentico 12 and Portal Engine Method

0 votesVote for this answer Mark as a Correct answer

David te Kloese answered on November 3, 2021 09:54

Ok! Where are you placing the macro itself. On a template, form tab of a page, page (widget) or desing (web part) tab?

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.