We are creating a page where components are fetched on page using broker DB query and are being published from CMS. And for each component, there is a need to get the difference between the published time for the component and current time.

The current server time is being captured at the page level using DateTime.Now syntax while the published time for each component is taken using the same code at component level C# TBB. The difference between the two values is to be shown on the page for each component. Thus, this calculation needs to be done at component level TBB. A scriptlet, where this difference is evaluated, is written at component level TBB.

But since the components are appearing dynamically on the page, the scriptlet doesn't get evaluated and appears as plain text on the page. Scriplet code is as

DateTime diff= pageTime - componentTime ; 

pageTime is a variable that captures the current server time and is present in page TBB and componentTime is the variable that captures the component published time in component TBB. and this line is written inside a component TBB since this calculation is required for each component on page.

Is there any way to achieve this? Any help will be much appreciated..

  • 1
    Perhaps you could add some examples of the code you are outputting, and explain where your scriptlet is executed. It is not very clear what the problem is. It seems like you just need to output DateTime.Now in both the CT and the PT at render time, and then resolve the difference with your scriptlet on the Content Delivery Side. Or are you trying to track a deployment time or something? Oct 24, 2014 at 11:47
  • Hi Chris, I need to check how old the component is i.e how many minutes or hours before it got published and display the same on the page.So I am trying to evaluate the difference between the published time and current server time in a scriptlet present in the component TBB
    – user961
    Oct 27, 2014 at 6:08
  • I think I am still missing something here. The TBB is executed AT PUBLISH TIME, so the Publish Time and Current Time are essentially the same.Are you trying to compare the Publishing time to the modification date of the component? If so, just use someting like DateTime.Now - componentTime Oct 27, 2014 at 11:47
  • Is your issue that pageTime is empty? Oct 27, 2014 at 11:51

4 Answers 4


I agree with Nuno: your problem is really that the content of the component presentation does not get evaluated. Publishing the CPs as ASCX and retrieving them with the ComponentPresentationAssembler is one way to solve this.

The other is to write a REL renderer class which picks up a custom REL-tag like this:

<rel:currentTime />

A REL renderer is written in Java. More information can be found in these blog posts:


Given that your Component Presentation could be published independently from your Page (or by multiple Pages), you can't do the "compare" at publish time. You will need to calculate this at page assembly/request time on the presentation server using either server-side or client side scripts.

If Page A uses Component Presentation X, the time difference will be different than when Page B uses Component Presentation X.

Alternatively, if you are trying to compare the modification time of your Component with the publishing time of the Component, then you should just subtract the modification time from the current DateTime (because your TBB/CT is executed at publish time).


I guess the way your question is worded has misled us to think that the problem is related to the time calculation, when actually it's just about DCP configuration

the scriptlet doesn't get evaluated and appears as plain text on the page

Component Presentations have a field defining their "Output Format". This is what tells Tridion what to do when reading a DCP, and by default this format is set to a text format - HTML fragment. HTML fragments get sent to the browser "as is", since they have no dynamic code. Given you're using .NET you may want to try using "ASCX Control" instead with the caveat that ASCX DCPs must be published to the file system to execute.

Another alternative here would be to use something that is executed on the browser, with Javascript, instead of a server-side language. You can get the published date using the same method you use today, and then get the current time/date using standard javascript.


Note that this information is also stored in the broker as the 'LastPublicationDate' property on the 'IPageMeta' and 'IComponentMeta' classes; as such you don't have to write out this as code in your component template but you could let your page template output calculate the value needed from this property instead (thus bypassing the ASCX DCP limitation as mentioned by Nuno).

Below code calculates how "old" the page and embedded component presentations are:

TcmUri pageUri = new TcmUri("tcm:1-2-64");
PageMetaFactory pmf = new PageMetaFactory(pageUri.PublicationId);
IPageMeta pageMeta = pmf.GetMeta(pageUri.ItemId);
TimeSpan pageAge = (DateTime.Now - pageMeta.LastPublicationDate);

ComponentMetaFactory cmf = new ComponentMetaFactory(pageUri.PublicationId);
foreach (ComponentPresentationMeta cpMeta in pageMeta.ComponentPresentationMeta)
    IComponentMeta componentMeta = cmf.GetMeta(cpMeta.ComponentId);
    TimeSpan componentAge = (DateTime.Now - componentMeta.LastPublicationDate);

Note that this code has to run inside your .aspx page (so not in your template) and that you should of course ensure that "tcm:1-2-64" is replaced with the actual TcmUri of your page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.