Alterian ACM : Getting A List Of Child Pages

Today’s quick guide will demonstrate how to get a list of child pages from the ACM API.  First, we need to get the current page item that the page is trying to load.  As we’re using ACM we can never be sure if the current page has been created using the ‘Site planner’ or the ‘Content Explorer’ so on every request we need to check if the current item is a reference item or not .

public IItem GetCurrentItem()
{
var dp = new DataProvider(ReturnFields.All);
var current = dp.GetItem(url);
if (current.IsReferenceItem)
{
current = current.GetReferredToItem();
}
return current;
}
}

After we reference to the current item, we need to query the API to get the items child pages; this is done using the getBoundItems method.  My main issue with this method is that it returns a collection of ILinks instead of IItems, this means you cannot just get the item data with one call and you have to parse the list into IITems before you can do anything useful.  In order to convert ILinks into IItems all you need to do is make the following call :

      var childPages = iLinks.Where(link => link != null).Select(link => link.ChildItem);

So to pull everything all together :

  • Get the current item
    var currentPage = GetCurrentItem()
  • Get all the child pages as ILinks
    var iLinks= currentPage.getBoundItems("Page Content Type", CMSortField.ORDERING, false, 0, "Standard");
  • Converts the ILinks to IITems
    var iItems = iLinks.Where(link => link != null).Select(link => link.ChildItem);

At this point I would recommend converting all your IItems into content type specific POCOs.  The main reason why I recommend this approach is because when you try debugging your code and you try to look inside an ITem, all you will see is a ‘Function Evaluation Timeout Error’ useful!  As this makes debugging very frustrating, manually copying into your own object will make your life much easier, especially if you use utilise the new strongly type data controls available in .NET 4.5.  So

     items = childPages.Select(x => ObjectFactory.CreatePage(x);

This Create Page method will then build up your object based on the Content Type you are calling, e.g.

    public Page CreatePage(IItem item)
{
var dp = new DataProvider();
var childItem = dp.GetIItem(item.getUrl);
var page = new PageObject
{
Title =   childItem.GetFieldValue("title");
etc...
}
}

Jon D Jones

Software Architect, Programmer and Technologist Jon Jones is founder and CEO of London-based tech firm Digital Prompt. He has been working in the field for nearly a decade, specializing in new technologies and technical solution research in the web business. A passionate blogger by heart , speaker & consultant from England.. always on the hunt for the next challenge

More Posts