MVC: Top-level Navigation, Sitemap Page on a Live Site

JanL@kentico.com[email protected] Czech RepublicMember, Administrator, Kentico Staff admin
edited February 2017 in Back-end Development

On top of another discussion about sitemaps, we've been thinking about generating navigation and sitemap pages for live sites automatically.

The logic in the aforementioned discussion is a prerequisite. But, once the routes are 'known' at the MVC side, another page with the stub of the top-level navigation code could be generated. It could be a partial view, display template, tag helper or a combination of them.

The navigation page could then be referenced from within the _Layout.cshtml file.

Moreover, with the new tag helpers in ASP.NET Core it could even be possible to regenerate the navigation markup after the sitemap in Draft has changed.

The logic could generate a .NET constant object that contains the structure of the sitemap in an abstract way.

Example:

The above could become:

public class SitemapNode
{
    public string CodeName { get; set; }
    public string Title { get; set; }
    public List<SitemapNode> Subnodes { get; set; }
}

public const List<SitemapNode> Sitemap = new List<SitemapNode>
{
    new SitemapNode
    {
        CodeName = "home",
        Title = "Home",
    },

    new SitemapNode
    {
        CodeName = "products",
        Title = "Products",

        Subnodes = new List<SitemapNode>
        {
            new SitemapNode
            {
                CodeName = "coffee",
                Title = "Coffee",
            },

            new SitemapNode
            {
                CodeName = "brewers",
                Title = "Brewers",
            },

            // ...
        }
    }

    // ...
}

Then, the rendering of the markup could be handled by tag helpers. One tag helper could render the top navigation and another could deal with rendering the full sitemap. This way it would be possible to regenerate the sitemap to the MVC side without forcing you to retype the markup code.

Let's discuss these questions:

  • Does such an automation logic (tool) make sense to you? Why does it/doesn't it make sense?
  • Do the visuals of your navigation rely rather on CSS or does each menu item require to write lots of HTML?
  • Do you plan on jumping into the world of ASP.NET Core soon?

Feel free to discuss the topic here! We'd love to hear if this is what you'd use in your projects. Then, we could write an article and discuss how we can improve the Deliver .NET SDK, together with the community.

Comments

Sign In or Register to comment.