【问题标题】:How to check publishing or rendering context with TOM.NET?如何使用 TOM.NET 检查发布或呈现上下文?
【发布时间】:2013-01-28 18:39:39
【问题描述】:

SDL Tridion 的内容管理器模板 API (TOM.NET) 提供了检测发布或呈现上下文的方法。

用例

  • 向特定环境提供调试信息(例如,TCM Uris only on Staging)
  • 在预览中显示不同的标记(例如显示指向已发布页面的链接)
  • 在 Experience Manager 或 SiteEdit 中显示不同的可创作字段

我已经看过并尝试了一些示例,但在关注同事 StanEric 之间的聊天后,我想确保我关注 TOM.NET(6.1 / Tridion 2011)。

场景

  1. 发布到特定的发布目标(通常是“实时”和“暂存”)
  2. 内容管理器浏览器(CME) 预览
  3. 会话预览 Experience Manager (XPM) 渲染
  4. (已添加)模板生成器

1。发布到目标(或从发布)

Tridion.ContentManager.Publishing.PublishEngine.GetPublishInfo(IdentifiableObject item)

Item 将是一个页面或组件。这将返回 PublishInfo 对象的集合,其中包括 PublicationTarget 以确认您要发布到的位置。

Tridion.ContentManager.Templating.PublishingContext.PublicationTarget 也有 PublicationTarget

2。芝商所预览

PublicationTarget 是null,这是有道理的,因为您没有 Publication Target 。 :-)

3。会话预览

使用Tridion.ContentManager.Publishing下的RenderMode枚举,它有:

  • “发布”(0)
  • 'PreviewStatic' (1)
  • 'PreviewDynamic' (2)

对于 Session Preview,PublicationTarget 不会是 null,这并不是真正的发布

4。 (添加)模板生成器

?

Alexander Klock also describes some related examples 涵盖了除 CME Preview 之外的大部分内容。

问题

  • 我是否遗漏了任何场景?发布到特定发布目标、定期预览和 XPM 会话预览?

  • 我应该如何避免硬编码 PublicationTargets(例如检查字符串值而不是 TCM Uris 更好)?

  • 更新:根据 Vikas 的回答将模板生成器添加到列表中,我怎么知道我在模板生成器中进行渲染?

【问题讨论】:

  • 好问题,有用的答案。谢谢!

标签: tridion


【解决方案1】:

你真的需要一个关于这个问题的 tl;dr...

这是我所知道的:

模板生成器

发布目标为 null,RenderMode 为 PreviewDynamic

CME 预览

发布目标 ID 为 tcm:0-0-0(或TcmUri.UriNull),RenderMode 为 PreviewDynamic

会话预览

Publication Target ID为真实目标ID,RenderMode为PreviewDynamic

发布

Publication Target ID是真实的,RenderMode是Publish

编辑

这是我最近编写的一些示例代码,用于确定当前模式。

private CurrentMode GetCurrentMode()
{
    RenderMode renderMode = _engine.RenderMode;
    if (renderMode == RenderMode.Publish) return CurrentMode.Publish;


    if (renderMode == RenderMode.PreviewDynamic)
    {
        if (_engine.PublishingContext.PublicationTarget == null) return CurrentMode.TemplateBuilder;
        PublicationTarget target = _engine.PublishingContext.PublicationTarget;
        if (target.Id.Equals(TcmUri.UriNull)) return CurrentMode.CmePreview;
        return CurrentMode.SessionPreview;
    }
    return CurrentMode.Unknown;
}

private enum CurrentMode
{
    TemplateBuilder,
    CmePreview,
    SessionPreview,
    Publish,
    Unknown
}

【讨论】:

  • 还有被否决的风险?我应该写一篇博文。 :-p +1 给 Vikas 和你的答案。接受在模板生成器上回答。
【解决方案2】:

您很好地展示了完整的发布/预览模型。这是我的想法..

Are we missing any scenarios? 

我认为您涵盖了除模板构建器案例之外的所有内容,这类似于 CME 预览,我们将发布目标设为空,但可用于检查对于调试目的非常重要的不同条件。 p>

How should I avoid hard-coding PublicationTargets  

是的,我们不应该在任何代码中使用 tcm uri,因为您建议我们可以使用 name,甚至 name 可以在该程序的相应配置文件中配置。

这里也可能不相关,为 Tridion UI 编辑设置单独的目标总是好的,而不是 staging。两者都可以在具有两个部署者的同一服务器上进行配置。一个可能是 staging.yoursite.com,另一个可能是 tridionui.yoursite.com

谢谢..

【讨论】:

  • 很好,我们还能检查什么来确认我们是否在模板生成器中运行?我注意到@@ID@@ 在模板生成器中给了我一个组件 ID,但在其他上下文中给了我一个模板 ID。不过,这可能不是最好的检查方式。
  • 模板生成器的一个好处是您无需签入即可查看更改,您可以打开模板、tbb 或任何其他上下文项并仅在保存时查看不同的结果。
  • 没错,它至少在 2011 年可以在较小版本的模板上运行。保存并运行。但是如何检查我是否在模板生成器中运行?
猜你喜欢
  • 2012-11-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-07
  • 2012-06-08
  • 1970-01-01
  • 1970-01-01
  • 2012-10-23
相关资源
最近更新 更多