【问题标题】:How to get the published timestamp of a page or component using SDL Tridion TOM.NET API如何使用 SDL Tridion TOM.NET API 获取页面或组件的已发布时间戳
【发布时间】:2012-04-10 15:56:26
【问题描述】:

我正在尝试使用 TOM.NET API 将给定页面或组件的已发布时间戳保存到给定目标。在 PageComponent 对象下不是很明显,有人能指出我正确的方向吗?

【问题讨论】:

  • 您能解释一下您何时尝试访问此信息吗?是在呈现页面或组件时,还是在发布后的某个时间点?您是否还需要了解特定目标的此信息?

标签: tridion


【解决方案1】:

您可以为此使用PublishEngine.GetPublishInfo(IdentifiableObject) 方法,它返回PublishInfo 对象的集合,其中包含可用于给定项目的日期和其他(发布)信息。

【讨论】:

    【解决方案2】:

    感谢 Bart 在上面的回答,我敲出了以下粗略的代码。这与性能无关,因为这是向客户演示某些东西的概念证明:

    // if we are in publishing mode, figure out the target we are publishing to, and get the timestamp that the page is published to this target
    if (engine.PublishingContext.PublicationTarget != null)
    {
      ICollection<PublishInfo> publishCollections = PublishEngine.GetPublishInfo(childPage);
      foreach (PublishInfo publishInfo in publishCollections)
      {
         if (publishInfo.PublicationTarget == engine.PublishingContext.PublicationTarget)
         {
            pageElem.SetAttribute("timestamp", publishInfo.PublishedAt.ToString());
         }
       }
    }
    

    在这里你可以看到我已经有了我的childPage 对象,我正在将结果添加到现有的页面 XML 对象 (pageElem.SetAttribute("timestamp", publishInfo.PublishedAt.ToString())) - 所以如果使用这个 sn-p,请注意这些项目 :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-11-22
      • 1970-01-01
      • 2012-09-29
      • 1970-01-01
      • 1970-01-01
      • 2012-08-17
      • 1970-01-01
      相关资源
      最近更新 更多