We are developing a .net based CT based on Broker query Mechanism (filter):
ComponentPresentationAssembler cpAssembler = new ComponentPresentationAssembler(Page ID,Page object);
In order to pass the page ID, I need to get the access of page on which the component is present. How can I access the page from package? Since this a CT, a component object would be available in page and not a page object. Tried the following piece of code, but without success:
string pageURI = _package.GetValue("Page.ID");
Page objPage = (Page)_engine.GetSession().GetObject(pageURI);
This is not working as there is no page object. What are the alternatives so that we can access the parent page of component from CT?
To address this I created an AddPageToComponentPresentation TBB. Here's 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");
}
}
}
}
Thanks a lot Jeremy. I tried this code, but was not able to use the interface TemplateBase
With hints from your code, I tried
Page page = _engine.PublishingContext.RenderContext.ContextItem as Page;
and this worked well. Also I could get publication object as:
Publication pub = (Publication)page.ContextRepository;
Thank you very much.
来源:https://stackoverflow.com/questions/12562360/access-container-page-of-a-component-in-net-based-ct