获取组件的根发布 [英] Getting root publication of component
问题描述
让我们假设有以下出版物来解决这个问题.
Let’s assume the following publications for this question.
20 内容 -> tcm:0-20-1
20 Content -> tcm:0-20-1
…
…
…
70 网页 -> tcm:0-121-1
70 Web -> tcm:0-121-1
我在 (20 Content) 出版物下创建了一个组件,我正在从其中一个子出版物 (70 Web) 发布此组件.我正在使用 Dreamweaver 模板编写 UI,我正在从 DWT 调用 C# 自定义函数.在发布时,该组件在组件展示中将被称为 121-432.有没有办法获得组件创建位置的根发布?那就是我应该得到 20-432,而不是得到 121-432.
I’ve a component created under (20 Content) publication and I’m publishing this component from one of the child publications (70 Web). I’m using Dreamweaver template to write UI and I'm calling C# custom functions from DWT. While publishing, this component will be referred as 121-432 in component presentation. Is there any way to get the root publication of where the component is created? That’s I should get 20-432, instead of getting 121-432.
我尝试了 Component.GetBluePrintChain() 并返回一个包含所有蓝图层次结构的列表.我可以从该列表中获取第 1 项,以获取该组件及其实际创建的发布位置.
I’ve tried Component.GetBluePrintChain() and it returns a list that has all the blueprint hierarchy. I could get 1st item from this list to get this component with the publication where it is actually created.
因为我必须在很多地方调用这个方法,所以我只是想检查是否有其他直接/更好的方法来完成这个.
Since I’ll have to call this method in many places, I just wanted to check if there any other direct/better way to get this done.
有人可以推荐吗?
推荐答案
您需要查看组件的 OwningRepository
属性,因此:
You'll want to look at the OwningRepository
property of the Component, so:
var componentIdInOwningPublication = new TcmUri(
component.Id.ItemId,
ItemType.Component,
component.OwningRepository.Id.ItemId
);
将其放入自定义 Dreamweaver 可调用函数中,您应该就可以开始使用了.
Put that into a custom Dreamweaver-callable function and you should be good to go.
更新还有一个名为 CreateTcmUriForPublication
的辅助方法可以进行翻译.所以你也可以像这样调用那个:
Update
There also is a helper method called CreateTcmUriForPublication
that does the translation. So you could also invoke that one like this:
var componentIdInOwningPublication = TemplateUtilities.CreateTcmUriForPublication(
component.OwningRepository.Id.ItemId,
component.Id
);
两个片段的最终结果是相同的:组件在其拥有的存储库上下文中的 TcmUri.
The end result of both snippets is the same though: the TcmUri of the Component in the context of its owning repository.
这篇关于获取组件的根发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!