The SDL Tridion Content Manager templating API (TOM.NET) offers ways to detect publication or rendering context.
Use cases
- Present debugging information for a specific environment (for example, TCM Uris only at the stage)
- Show another markup in preview mode (for example, show a link to a published page)
- Show different fields available to authors in the Experience Manager or SiteEdit
I have seen and tried several examples, but after talking between colleagues Stan and Eric , I want to make sure that I follow TOM.NET (6.1 / Tridion 2011).
Scenarios
- Publish to a specific publication purpose (usually "Live" and "Staging")
- Content Manager Explorer (CME) Explorer Preview
- Preview Rendering Session for Experience Manager (XPM)
- (Added) Template Designer
1. Publication to the target (or from the publication)
Tridion.ContentManager.Publishing.PublishEngine.GetPublishInfo(IdentifiableObject item)
The item will be a page or component. This returns a collection of PublishInfo objects that includes a PublicationTarget to validate where you are publishing.
Tridion.ContentManager.Templating.PublishingContext.PublicationTarget has a PublicationTarget .
2. CME preview
PublicationTarget is null , which makes sense because you have no purpose for publishing. :-)
3. Session Preview
Use the RenderMode Enum in the Tridion.ContentManager.Publishing section, which has:
- 'Publish' (0)
- 'PreviewStatic' (1)
- 'PreviewDynamic' (2)
PublicationTarget will not be null to preview a session that is not being published.
4. (Added) Template Builder
Alexander Klok also describes some related examples that cover most of them, besides CME preview.
Question (s)
Did I miss any scripts? Publish to targeted publication publication, regular preview, and preview of an XPM session
How can I avoid hard coding PublicationTargets (for example, it is better to check string values instead of TCM Uris)?
Update: added a template to the list on Vikas answer , how do I know if I am rendering inside the Template Builder?
source share