有没有办法从不是 Kentico 中的 CurrentDocument 的页面关系的左侧获取相关页面

问题描述

我需要使用页面关系从任何辅助页面(1,2,3,4...)访问主页信息,然后从主页检索关系列表,在本例中为 SecondaryPage1,SecondaryPage2,SecondaryPage3,等等。

我有以下结构 MainPage页面类型,例如文章isRelatedTo

  • SecondaryPage1页面类型:例如项目)
  • SecondaryPage2页面类型:例如项目)
  • SecondaryPage3页面类型:例如项目)
  • SecondaryPage4页面类型:例如项目)
  • SecondaryPage5页面类型:例如项目)

有没有简单的方法来做到这一点?我正在使用 CMSRepeater 来显示项目。我正在考虑为这个特定场景创建一个自定义的 CMSRepeater,但我想知道是否有不同的方法

所以,回顾一下,SecondaryPage1 isRelatedTo MainPage 在右侧。

MainPage -> isRelatedTo -> SecondaryPage1

我正在尝试从 MainPage 显示整个列表,我需要访问任何二级页面上的信息。


我创建了这段代码,它运行良好,我只是想发现是否有更简单的解决方案或替代方案。

....

List<CMS.DocumentEngine.TreeNode> mainRelatedItems = new List<CMS.DocumentEngine.TreeNode>();

mainRelatedItems.AddRange(DocumentHelper.GetDocuments().Types(PageTypes.Split(';')).InRelationWith(CurrentDocument.NodeGUID,PageRelationship,relationshipSide));

List<CMS.DocumentEngine.TreeNode> secondaryRelatedItems = new List<CMS.DocumentEngine.TreeNode>();

foreach (CMS.DocumentEngine.TreeNode item in mainRelatedItems)
{

if(ExcludeCurrentDocument)
            secondaryRelatedItems.AddRange(DocumentHelper.GetDocuments().Types(PageTypes.Split(';')).InRelationWith(item.NodeGUID,SecondLevelPageRelationship,secondaryRelationshipSide).Where(x => x.NodeGUID != CurrentDocument.NodeGUID));
else
            secondaryRelatedItems.AddRange(DocumentHelper.GetDocuments().Types(PageTypes.Split(';')).InRelationWith(item.NodeGUID,secondaryRelationshipSide));

}
....

Customrepeater.ItemTemplate = TransformationHelper.LoadTransformation(Customrepeater,TransformationName);
Customrepeater.DataSource = secondaryRelatedItems;
Customrepeater.DataBind();

....

解决方法

在您的文档查询中,您可以指定关系 GUID 以及方和关系名称。它不必是当前文档。

DocumentHelper.GetDocuments().InRelationWith(guid,"reltionshipname",side)

** 更新 **

根据您问题的最新更新,您需要通过 URL 参数或会话或其他一些参数获取主文档 ID/guid,然后使用类似 DocumentHelper.GetDocument(MainDocID) 的内容查找该节点。获得主文档后,您可以使用我上面提供的代码执行查找。

听起来您没有很好的方法来获取此信息,因为其中一个辅助页面可能与许多其他页面或页面类型相关。一种建议可能是创建一个非常具体的关系名称,然后通过该非常具体的关系名称和辅助页面 ID 查询您的主文档,以获取可能与其相关的任何主页面。