Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Richard Galt 50 posts 186 karma points
    Dec 10, 2014 @ 15:02
    Richard Galt
    0

    A to Z search multiple nodes at root

    I'm trying to generate an a to z listings from the children of 2 nodes.

    The nodes at root are "Home" and "A to Z Entries folder".

    My existing script listed the Home node correctly:

    @if (!string.IsNullOrEmpty(Request.QueryString["letter"]))    
    {
        var letter = Request.QueryString["letter"].ToUpper().Substring(0,1) ;
    
        var root = Model.Content.AncestorOrSelf(1);
        var nodes = root.DescendantsOrSelf().Where( x => x.IsVisible() && x.Name.ToUpper().StartsWith(letter) ).OrderBy("Name");    
    
        <h2>@letter</h2>
    
        if ( nodes.Any() )
        {
            <ul>    
            @foreach(var node in nodes)
            {
                <li><a href="@node.Url">@node.Name</a></li>
            }
            </ul>
    
        }   
    }
    

    I was advised to look at TypedContentAtRoot()

    I can get the root nodes to appear in the a to z listing but not the children. I need to get the children specifically of "Home" and "A to Z Entries folder"

    My test code:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    
    
    @if (!string.IsNullOrEmpty(Request.QueryString["letter"]))    
    {
        var letter = Request.QueryString["letter"].ToUpper().Substring(0,1);
    
        <h2>@letter</h2>
            <ul>    
            @foreach (var child in Umbraco.TypedContentAtRoot().Where( x => x.IsVisible() && x.Name.ToUpper().StartsWith(letter)).OrderBy("Name"))
    
            {
             <a href="@child.Url">@child.Name</a>
            }
            </ul>   
    }
    

    Any help would be much appreciated.

    Cheers

    Rich

  • Richard Galt 50 posts 186 karma points
    Dec 12, 2014 @ 11:20
    Richard Galt
    100

    Managed to get this working with the following code:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    
    
    @if (!string.IsNullOrEmpty(Request.QueryString["letter"]))
    {
        var letter = Request.QueryString["letter"].ToUpper().Substring(0, 1);
        var Content = Umbraco.TypedContentAtRoot().DescendantsOrSelf("ContentPage");
        var AToZ = Umbraco.TypedContentAtRoot().DescendantsOrSelf("AToZEntry");
        var AllDocumentTypes = Content.Concat(AToZ);
    
        <h2>@letter</h2>
        <ul>
            @foreach (var node in AllDocumentTypes.Where(x => x.IsVisible() && x.Name.ToUpper().StartsWith(letter)).OrderBy("Name"))
            {
                <li><a href="@node.Url">@node.Name</a></li>
            }
        </ul>
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft