Copied to clipboard

Flag this post as spam?

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


  • Dominic Kelly 114 posts 133 karma points
    Jan 17, 2012 @ 18:11
    Dominic Kelly
    0

    Subnav - only display certain page types

    Ok so I have a gallery landing page with photos and video items and regular pages on the same branch:

    http://screencast.com/t/ZrV7rXqS

    And a sub nav on the gallery landing page:

    http://screencast.com/t/jlDKAVGu

    Basically, I only want to display 'Dummy 5' and not the images in the sub nav.

    What's best practice for doing this?

    The problem I see is that my gallery landing page could have any page type hanging off of it, so I could add a 'Show in sub nav' custom field, but that would require me to add that property to every data type, or I could filter my razor script to only show the data types I'm interested in, but that could end up being a massive list.

    My script is:

    <ul class="nav clearfix">
    @foreach (var level in @Model.AncestorsOrSelf(2).Where("Visible"))
    {
        if (@level.Level == 2)
        {
            foreach (var item in @level.Children.Where("Visible"))
            {
            <li><a class="@{if(@Model.Url == @item.Url){@Html.Raw("selected");}}" href="@item.Url">@item.Name</a></li>
            }
        }

    </ul>

     

     

  • Douglas Ludlow 210 posts 366 karma points
    Jan 17, 2012 @ 18:18
    Douglas Ludlow
    0

    Try something like this:

    <ul class="nav clearfix">
    @foreach (var level in @Model.AncestorsOrSelf(2).Where("Visible"))
    {
       
    if (@level.Level == 2)
        {
           
    foreach (var item in @level.Children.Where("Visible").Where("NodeTypeAlias == \"Folder\"))
            {
            <li><a class="@{if(@Model.Url == @item.Url){@Html.Raw("selected");}}" href="@item.Url">@item.Name</a></li>
            }
        }
    }
    </ul>

    Or you might be able to do something like this:

    foreach (var item in @level.Folder.Where("Visible")) {...}

    Of course you'd have to replace Folder with the actual document type.

  • Dominic Kelly 114 posts 133 karma points
    Jan 17, 2012 @ 18:23
    Dominic Kelly
    0

    Dummy 5 is actually not a folder, it's a 'page' of content of a particular data type. 

  • Douglas Ludlow 210 posts 366 karma points
    Jan 17, 2012 @ 18:25
    Douglas Ludlow
    0

    Yeah, you'd have to substitude "Folder" with the actual document type alias.

  • Dominic Kelly 114 posts 133 karma points
    Jan 17, 2012 @ 18:26
    Dominic Kelly
    0

    As in this?

    http://screencast.com/t/dLVY5Bccmrq

    The problem here is that I have many types... Seems cumbersome to list every individual type that should or should not appear on the nav. 

  • Rodion Novoselov 694 posts 859 karma points
    Jan 17, 2012 @ 18:30
    Rodion Novoselov
    0

    If you in fact need only the first child item you can select it with:

    @Model.Children.First()
  • Douglas Ludlow 210 posts 366 karma points
    Jan 17, 2012 @ 18:32
    Douglas Ludlow
    0

    I don't think he's looking for the first item. He's looking to filter the results. I  know of no other "magic" way to filter those results than by adding a property to the Document Type or using the NodeTypeAlias.

  • Dominic Kelly 114 posts 133 karma points
    Jan 17, 2012 @ 18:33
    Dominic Kelly
    0

    Hmm. Well that won't work either:

    http://screencast.com/t/YxOIaR4qtL

    Dummy and Another Page need to show, but nothing else should.

    My Sub Nav is in the master page, so I guess the only way around this is to add:

    .Where("NodeTypeAlias" != "Gallery Item").Where("NodeTypeAlias" != "Promotion Item")

    etc

    Is that the only way to do it? No internal way of determining a data type is a stranged piece of content, or an actual page?

  • Dominic Kelly 114 posts 133 karma points
    Jan 17, 2012 @ 18:34
    Dominic Kelly
    0

    "I don't think he's looking for the first item. He's looking to filter the results. I  know of no other "magic" way to filter those results than by adding a property to the Document Type or using the NodeTypeAlias."

    Yup. That's what I thought.

  • Dominic Kelly 114 posts 133 karma points
    Jan 17, 2012 @ 18:37
    Dominic Kelly
    0

    @foreach (var level in @Model.AncestorsOrSelf(2).Where("Visible"))

    {

        if (@level.Level == 2)

        {

            foreach (var item in @level.Children.Where("Visible").Where("NodeTypeAlias" != "GalleryMediaItem"))

            {

            <li><aclass="@{if(@Model.Url == @item.Url){@Html.Raw("selected");}}"href="@item.Url">@item.Name</a></li>

            }

        }

     

    Doesn't seem to work...

  • Rodion Novoselov 694 posts 859 karma points
    Jan 17, 2012 @ 18:38
    Rodion Novoselov
    0

    I've thought that you could just declare some property for the document types you need to show without asigning it any value and filter you content with HasProperty() method.

  • Dominic Kelly 114 posts 133 karma points
    Jan 17, 2012 @ 18:40
    Dominic Kelly
    0

    .Where("NodeTypeAlias" != "GalleryMediaItem"))

    Will do the job if I knew the syntax!

  • Douglas Ludlow 210 posts 366 karma points
    Jan 17, 2012 @ 18:40
    Douglas Ludlow
    0

    Careful with the syntax. Refer to Umbraco Razor Feature Walkthrough – Part 4 for the correct syntax. Should be:

    foreach (var item in @level.Children.Where("Visible").Where("NodeTypeAlias != \"GalleryMediaItem\"")) {...}
  • Dominic Kelly 114 posts 133 karma points
    Jan 17, 2012 @ 18:44
    Dominic Kelly
    0

    Got it thanks!

  • Rodion Novoselov 694 posts 859 karma points
    Jan 17, 2012 @ 18:56
    Rodion Novoselov
    0

    You can also use the parameterized syntax:

    blablabla.Where("NodeTypeAlias != @0", "GalleryMediaItem")

     (Personally I prefer it so that not to mess about with backslashes)

  • Dominic Kelly 114 posts 133 karma points
    Jan 17, 2012 @ 18:57
    Dominic Kelly
    0

    Sweet cheers.

  • Douglas Ludlow 210 posts 366 karma points
    Jan 17, 2012 @ 19:03
    Douglas Ludlow
    0

    That's pretty neat. I didn't know about the parameterized syntax.

Please Sign in or register to post replies

Write your reply to:

Draft