kenticokentico-11

Is there a way to get the related pages from a left side of the page relationship that is not the CurrentDocument in Kentico


I need to access to the Main Page information from any of the Secondary Pages (1,2,3,4...) using a page relationship, and then retrieve the relationship list from the main page, in this case SecondaryPage1,SecondaryPage2,SecondaryPage3, etc..

I have the following structure MainPage (Page Type e.g. Article) isRelatedTo:

Is there an easy way to do it? I am using a CMSRepeater to display the items. I am thinking on creating a custom CMSRepeater for this specific scenario but I would like to know if there is a different approach.

So, to recap, The SecondaryPage1 isRelatedTo MainPage on the right side.

MainPage -> isRelatedTo -> SecondaryPage1

I am trying the display whole list from the MainPage, I need to access to that information on any of the secondary pages.


I created this code, it works pretty well I am just trying to discover is there is simpler solution or if there is an alternative.

....

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, SecondLevelPageRelationship, secondaryRelationshipSide));

}
....

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

....

Solution

  • In your document query, you can specify the relationship GUID as well as the side and relationship name. It doesn't have to be the current document.

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

    ** UPDATE **

    Based on the most recent update of your question, you'd need to get the Main document id/guid by URL parameter or session or some other parameter, then look that node up using something like DocumentHelper.GetDocument(MainDocID). After you have that Main document, you can perform your lookup using the code I provided above.

    It doesn't sound like you have a great way to get this info simply because one of those Secondary pages could be related to possibly many other pages or page types. One suggestion may be to create a very specific relationship name and simply query your Main document by that very specific relationship name and the Secondary page ID to get any Main pages that may be related to it.