Search code examples
asp.netrazorc1-cms

How do i create a navigation function that returns websites in my composite c1 portal?


I want to create a function (prefer razor) that returns a list of websites in my portal.

I found @HomePageNode and able to process childs from there, but thats only the active website.

I added another website next to the defaut "Front Page" and would like to put in a switcher at the top automatic if i add others also later.

Composite C1 is a CMS System


Solution

  • You can use Composite.Data.SitemapNavigator.HomepageNodes:

    Gets PageNode's for all homepages.

    Example:

    using(var conn = new DataConnection())
    {
        var navigator = new SitemapNavigator(conn);
        IEnumerable<PageNode> homePageNodes = navigator.HomePageNodes;
    }
    

    Now you have the PageNodes of all your homepages and can traverse them recursively via ChildNodes.


    There also are other functions in SitemapNavigator you might prefer depending on your circumstances, like AllSitemapsXML or HomepageIDs.

    You will find them all in the Composite API.