Access container page of a component in .net based CT

孤街浪徒 提交于 2019-12-05 12:37:42

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!