Copied to clipboard

Flag this post as spam?

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


  • Lee 1130 posts 3088 karma points
    May 06, 2011 @ 07:17
    Lee
    0

    Getting Nodes By Level & DocType

    I am trying to create a simple navigation but seem to be struggling... This is not working when I thought it should?  Any tips appreciated.

    @inherits umbraco.MacroEngines.DynamicNodeContext
    @{     
        var level = String.IsNullOrEmpty(Parameter.Level) ? 1 : int.Parse(Parameter.Level);
        var bCategories = @Model.AncestorOrSelf(level);
    
        if (bCategories != null) {
            <ul id="mainnavigation">
                @foreach (var cat in bCategories.Children("nodeTypeAlias == \"BusinessCategory\"").Where("Visible").OrderBy("SortOrder")) 
                {
                    <li><a href="@cat.Url">@cat.Name</a></li>
                }
            </ul>
        }
    }

    I keep getting the error

    Cannot invoke a non-delegate type
  • Lee 1130 posts 3088 karma points
    May 06, 2011 @ 07:31
    Lee
    0

    Seems its where I call the DocType that is causing an issue, if I remove

    ("nodeTypeAlias == \"BusinessCategory\"")

    It works, but defeats te object as I need to filter by both level AND DcoType

  • Lee 1130 posts 3088 karma points
    May 06, 2011 @ 07:57
    Lee
    0

    Got it working in the end

    @inherits umbraco.MacroEngines.DynamicNodeContext
    @{     
        var level = String.IsNullOrEmpty(Parameter.Level) ? 1 : int.Parse(Parameter.Level);
        var bCategories = @Model.AncestorOrSelf(level);
    
        if (bCategories != null) {
            <ul id="mainnavigation">
                @foreach (var cat in bCategories.Children.Where("nodeTypeAlias == \"BusinessCategory\"").Where("Visible").OrderBy("SortOrder")) 
                {
                    <li><a href="@cat.Url">@cat.Name</a></li>
                }
            </ul>
        }
    }
  • Jonas Eriksson 930 posts 1825 karma points
    May 06, 2011 @ 08:28
    Jonas Eriksson
    0

    It's populating dynamicnodelists on nodetypealias - so this should actually also work (and I think orderby should be the default sort order, ?):

    @foreach (var cat in bCategories.BusinessCategory.Where("Visible"))
  • Jason Prothero 422 posts 1243 karma points MVP c-trib
    May 11, 2011 @ 22:37
    Jason Prothero
    0

    What if there are multiple nodeTypeAliases to check for?  Would Lee's solution be the correct way to do it then?

    Thanks,

    Jason

  • Paul Brown 39 posts 80 karma points
    Jul 27, 2013 @ 01:36
    Paul Brown
    0

    Lee

    You just saved my ass with:

    Where("nodeTypeAlias == \"BusinessCategory\"")

    I really needed to find a way in razor to stop all my DateFolders showing in nagivation.

    Thanks

    Paul

Please Sign in or register to post replies

Write your reply to:

Draft