7

With regards to publishing and rendering in TOM.NET, I know the following is true for the legacy publishing framework (pre Web 8):

Template Builder

PublicationTarget is null, RenderMode is PreviewDynamic

CME Preview

PublicationTarget ID is tcm:0-0-0 (or TcmUri.UriNull), RenderMode is PreviewDynamic

Session Preview

PublicationTarget ID is the real Target ID, RenderMode is PreviewDynamic

Publish

PublicationTarget ID is the real one, RenderMode is Publish

Then you can use the following example code to determine the current mode:

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
}

How does this change in the new publishing framework introduced in SDL Web 8?

4

If all is well, the same logic can still be used; the new publishing franework uses Topology Manager Mappings instead of Publication Targets, but you will find that there is still a PublicationTarget set in the API (a so-called emulated Publication Target). This is done for backward compatibility purposes.

If you want to avoid using (now deprecated) Publication Targets in your code, you can use Engine.PublishingContext.TargetType instead.

BTW: I was not aware that there is a difference between Template Builder (TemplateDebugHost) and CME Preview w.r.t. PublicationTarget; not sure if that (unintentional) distinction also exists when using Topology Manager based publishing.

  • In case I wanted to use Engine.PublishingContext.TargetType instead, what would the "rules" then be to make a distinction between preview and publish in the different scenarios? – Bart Koopman Jun 9 '17 at 10:58
  • Basically the same. Preview and Debugging do not have a Target Type, Session Preview and Publish do. The latter two can be distinguished by Render Mode. I think that Debugging can be detected by the type of Engine. – Rick Pannekoek Jun 9 '17 at 11:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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