Component container access page in .net based CT

We are developing a .NET-based network based on a broker request mechanism (filter):

ComponentPresentationAssembler cpAssembler = new ComponentPresentationAssembler(Page ID,Page object); 

To pass the page identifier, I need to access the page on which this component is present. How to access a page from a package? Since this is a CT, the component object will be available on the page, not the page object. I tried the following code snippet, but to no avail:

 string pageURI = _package.GetValue("Page.ID"); Page objPage = (Page)_engine.GetSession().GetObject(pageURI); 

This does not work because there is no page object. What are the alternatives so that we can access the component's parent page from CT?

+4
source share
2 answers

To solve this problem, I created TBB AddPageToComponentPresentation. Here is the code:

 using System; using System.Collections.Generic; using System.Text; using Tridion.ContentManager; using Tridion.ContentManager.Templating; using Tridion.ContentManager.Templating.Assembly; namespace Tridion.Extensions.ContentManager.Templating { [TcmTemplateTitle("Add Page To ComponentPresentation")] class AddPageToComponentPresentation : TemplateBase { public override void Transform(Engine engine, Package package) { if (engine.PublishingContext.RenderContext.ContextItem != null) { Item pageItem = package.CreateTridionItem(ContentType.Page, engine.PublishingContext.RenderContext.ContextItem.Id); package.PushItem("Page", pageItem); Logger.Debug("Page Item added to Package"); } else { Logger.Debug("No Context Item found"); } } } } 
+5
source

Thanks a lot to Jeremy. I tried this code but could not use the TemplateBase interface

With hints from your code, I tried

 Page page = _engine.PublishingContext.RenderContext.ContextItem as Page; 

and it worked well. Also I could get the publication object as:

 Publication pub = (Publication)page.ContextRepository; 

Thank you very much.

-1
source

Source: https://habr.com/ru/post/1435880/


All Articles