ASPX templates
Version 5.x > ASPX templates > Get immediate siblings View modes: 
User avatar
Member
Member
kheon-pixelmedia - 3/11/2011 2:52:31 PM
   
Get immediate siblings
Using the API I need to retrieve the immediate siblings in relation to the existing document/node to drive some footer navigation for previous/next page.

I have not been able to find anything to assist me with doing this in an efficient manner and was hoping someone could point me in the right direction. The docs don't provide me with what I want.

Please advise, thanks!

User avatar
Member
Member
eric.rovtar - 3/12/2011 9:59:42 AM
   
RE:Get immediate siblings
While this functionality is not built into the CMSContext properties, it's shouldn't be too hard to adapt from some of the documentation.

First, you'd need to select all the sibling nodes:
using CMS.SiteProvider;

DataSet ds = null;

// create a TreeProvider instance
UserInfo ui = UserInfoProvider.GetUserInfo("administrator");
CMS.TreeEngine.TreeProvider tree = new CMS.TreeEngine.TreeProvider(ui);

// get dataset of tree nodes specified by alias path and class names (separated by semicolon),
// the second parameter says whether to return default culture documents if the required
// document language version is not available
ds = tree.SelectNodes("CorporateSite","/Products/%", "en-us", True, "cms.menuitem;cms.products");

// do something with dataset ...


The trick here is to just use the path "./%". This will get all the documents under the current parent document.

Then you would just have to parse them to find where your current document is in the DataSet. After that, you can get the previous and next items.

Hope this gives you a starting place.

If you have any more questions, feel free to ask.

-Eric

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 3/13/2011 7:14:13 PM
   
RE:Get immediate siblings
Hi,

The immediate siblings will have the same value in NodeParentID property. So, you can easily find them in the returned dataset, or filter the data set by this property - by using SelectNodes method overload with WHERE condition parameter.

Best regards,
Juraj Ondrus

User avatar
Member
Member
kheon-pixelmedia - 3/16/2011 7:46:07 AM
   
RE:Get immediate siblings
Thanks all, I was able to get this working by pulling a list of nodes from the parent node and then I iterate through them to find the current node, grabbing the previous and next accordingly (with proper handling for first/last).